<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>ヒビノログ &#187; JavaScript</title>
	<atom:link href="http://blog.songs-inside.com/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.songs-inside.com</link>
	<description>個人的なメモを淡々と記録していくブログ。Twitterは@kurikazu</description>
	<lastBuildDate>Sat, 04 Feb 2012 15:26:43 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.songs-inside.com/category/javascript/feed" />
		<item>
		<title>複数のコンテンツ項目を自動的にスライド表示する</title>
		<link>http://blog.songs-inside.com/javascript/492</link>
		<comments>http://blog.songs-inside.com/javascript/492#comments</comments>
		<pubDate>Wed, 28 Sep 2011 13:07:38 +0000</pubDate>
		<dc:creator>kurikazu</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.songs-inside.com/?p=492</guid>
		<description><![CDATA[たとえば、Twitterのタイムラインを自分のブログなどに表示するとき、Twitterから公式に提供されているウィジェットを使えばほぼ問題無いのだけど、表示する発言に何らかのフィルタをかける等、TwitterのAPIを使 [...]]]></description>
			<content:encoded><![CDATA[<p>たとえば、Twitterのタイムラインを自分のブログなどに表示するとき、Twitterから公式に提供されているウィジェットを使えばほぼ問題無いのだけど、表示する発言に何らかのフィルタをかける等、TwitterのAPIを使って処理した結果を、動きを付けてスライド表示させたい、という場合。</p>
<p><a href="http://8works-web.com/demo/20090418/index.html" target="_blank">こちらのサイト</a>で紹介されているように、「<a href="http://jqueryfordesigners.com/simple-jquery-spy-effect/" target="_blank">Simple jQuery Spy Effect</a>」というJSがあるので、基本的にはこれを使うとよいです。</p>
<p>ただ、このスクリプトにはちょっと難点があって、1つの項目を表示する欄の高さが一定になっています。基準となるのは、先頭の項目の表示高さです。<br />
Twitterのつぶやきの長さは一定ではないので、表示に必要な高さも一定ではないのですが、スクリプトをそのまま使うと、2つめ以降の表示が途中で切れたり、余白ができたりしてちょっとカッコ悪いです。</p>
<p>ということで、ちょっと修正して、欄の高さを可変にしてみました。<br />
<span id="more-492"></span><br />
<a href="http://scripts.songs-inside.com/twitter/sample1.php" target="_blank">表示サンプル</a></p>
<p>JavaScriptサンプル</p>
<pre class="brush: jscript; title: ; notranslate">$(function () {
    $('ul.twitter').simpleSpy();
});
(function ($) {
$.fn.simpleSpy = function (limit, interval) {
    limit = limit || 5;
    interval = interval || 5000;
    return this.each(function () {
        // 1. setup
            // capture a cache of all the list items
            // chomp the list down to limit li elements
        var $list = $(this),
            $list2 = $('ul.twitter-dummy'),
            items = [], // uninitialised
            currentItem = limit,
            total = 0, // initialise later on
            height = '300px';
        // capture the cache
        $list.find('&gt; li').each(function () {
            items.push(&quot;&lt;li class='update clear clearfix'&gt;&quot; + $(this).html() + &quot;&lt;/li&gt;&quot;);
        });
        total = items.length;
        $list.find('&gt; li').filter(':gt(' + (limit - 1) + ')').remove();
        // 2. effect
        function spy() {
            // insert a new item with opacity and height of zero
            var $insert = $(items[currentItem]).css({
                height : 0,
                opacity : 0,
                display : 'none'
            }).prependTo($list);   

            // get real height
            var $insert2 = $(items[currentItem]).css({
                opacity : 0,
                display : 'none'
            }).prependTo($list2);
            height = $list2.find('&gt; li:first').height();

            // fade the LAST item out
            $list.find('&gt; li:last').animate({ opacity : 0}, 1000, function () {
                // increase the height of the NEW first item
                $insert.animate({ height : height }, 1000).animate({ opacity : 1 }, 1000);
                // AND at the same time - decrease the height of the LAST item
                // $(this).animate({ height : 0 }, 1000, function () {
                    // finally fade the first item in (and we can remove the last)
                    $(this).remove();
                // });
            });
            currentItem++;
            if (currentItem &gt;= total) {
                return;
            }
            setTimeout(spy, interval)
        }
        spy();
    });
};
})(jQuery);</pre>
<p>HTMLサンプル</p>
<pre class="brush: xml; title: ; notranslate">&lt;ul class=&quot;twitter&quot;&gt;
&lt;li class='update clear clearfix'&gt;つぶやきつぶやき&lt;/li&gt;
&lt;li class='update clear clearfix'&gt;つぶやきつぶやき&lt;/li&gt;
&lt;li class='update clear clearfix'&gt;つぶやきつぶやき&lt;/li&gt;
&lt;li class='update clear clearfix'&gt;つぶやきつぶやき&lt;/li&gt;
&lt;li class='update clear clearfix'&gt;つぶやきつぶやき&lt;/li&gt;
&lt;/ul&gt;
&lt;ul class='twitter-dummy'&gt;&lt;/ul&gt;</pre>
<p>概要としては以下の通り。
<ol>
<li>表示に必要な高さを得るために、表示場所と同じスタイルが適用されるulオブジェクトをもう１つ作ります（サンプルでは「twitter-dummy」というのを作ってます）［HTMLサンプル8行目］</li>
<li>そのオブジェクトに対してアイテムを追加します［JavaScriptサンプル34行目～］</li>
<li>ダミーのオブジェクトはheightを指定しないようにして、表示に必要な高さを取得します［JavaScriptサンプル38行目］</li>
<li>その高さを、本来の表示場所の表示高さに指定します［JavaScriptサンプル43行目］</li>
</ol>
<p>そうするとキレイにできますよ、と。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.songs-inside.com/javascript/492/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.songs-inside.com/javascript/492" />
	</item>
		<item>
		<title>submitの罠</title>
		<link>http://blog.songs-inside.com/javascript/173</link>
		<comments>http://blog.songs-inside.com/javascript/173#comments</comments>
		<pubDate>Fri, 15 Aug 2008 03:14:46 +0000</pubDate>
		<dc:creator>kurikazu</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.songs-inside.com/?p=173</guid>
		<description><![CDATA[submitボタンのname属性にsubmitと付けてしまうと、 JavaScriptで、 document.form.submit(); とやろうとするとエラーになる。]]></description>
			<content:encoded><![CDATA[<pre><span>submitボタンのname属性にsubmitと付けてしまうと、
JavaScriptで、
document.form.submit();
とやろうとするとエラーになる。</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.songs-inside.com/javascript/173/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.songs-inside.com/javascript/173" />
	</item>
	</channel>
</rss>

