<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[A.PAO designSTUDIO BLOG]]></title> 
<link>https://blog.apao.idv.tw/index.php</link> 
<description><![CDATA[A.PAO designSTUDIO 阿保工作室]]></description> 
<language>zh-tw</language> 
<copyright><![CDATA[A.PAO designSTUDIO BLOG]]></copyright>
<item>
<link>https://blog.apao.idv.tw/post//</link>
<title><![CDATA[圖片自動滑動切換效果 (JavaScript_SlideTrans)]]></title> 
<author>apao &lt;apao@www.apao.idv.tw&gt;</author>
<category><![CDATA[JavaScript]]></category>
<pubDate>Tue, 11 Oct 2011 04:34:16 +0000</pubDate> 
<guid>https://blog.apao.idv.tw/post//</guid> 
<description>
<![CDATA[ 
	<a href="https://blog.apao.idv.tw/attachment.php?fid=1241" target="_blank"><img src="https://blog.apao.idv.tw/attachment.php?fid=1241" class="insertimage" alt="點擊在新視窗中瀏覽此圖片" title="點擊在新視窗中瀏覽此圖片" border="0"/></a><br/><a href="http://www.cnblogs.com/cloudgamer/archive/2008/07/06/1236770.html" target="_blank">DEMO</a><br/><br/>程序說明<br/>原理就是通過不斷設置滑動對象的left(水平切換)和top(垂直切換)來實現圖片切換的動態效果。<br/>首先需要一個容器，程序會自動設置容器overflow為hidden，如果不是相對或絕對定位會同時設置position為relative，<br/>滑動對象會設置為絕對定位：<br/><div class="code">var p = CurrentStyle(this._container).position;<br/>p == &quot;relative&quot; &#124;&#124; p == &quot;absolute&quot; &#124;&#124; (this._container.style.position = &quot;relative&quot;);<br/>this._container.style.overflow = &quot;hidden&quot;;<br/>this._slider.style.position = &quot;absolute&quot;;<br/></div><br/>如果沒有設置Change切換參數屬性，會自動根據滑動對象獲取：<br/><div class="code">this.Change = this.options.Change ? this.options.Change :<br/>&nbsp;&nbsp;&nbsp;&nbsp;this._slider&#91;bVertical ? &quot;offsetHeight&quot; : &quot;offsetWidth&quot;&#93; / this._count;<br/></div><br/>執行Run方法就會開始進入切換，其中有一個可選參數用來重新設置要切換的圖片索引：<br/><div class="code">index == undefined &amp;&amp; (index = this.Index);<br/>index &lt; 0 &amp;&amp; (index = this._count - 1) &#124;&#124; index &gt;= this._count &amp;&amp; (index = 0);<br/></div><br/>之後就到設置使用tween緩動時需要的參數了，<br/>包括_target(目標值)、_t(時間)、_b(初始值)和_c(變化量)：<br/><div class="code">this._target = -Math.abs(this.Change) * (this.Index = index);<br/>this._t = 0;<br/>this._b = parseInt(CurrentStyle(this._slider)&#91;this.options.Vertical ? &quot;top&quot; : &quot;left&quot;&#93;);<br/>this._c = this._target - this._b;<br/></div><br/>還有Duration(持續時間)是自定義屬性。<br/>參數設置好後就執行Move程序開始移動了。<br/>裡面很簡單，首先判斷_c是否有值（等於0表示不需要移動）和_t是否到達Duration，<br/>未滿足條件就繼續移動，否則直接移動到目標值並進行下一次切換：<br/><div class="code">if (this._c &amp;&amp; this._t &lt; this.Duration) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.MoveTo(Math.round(this.Tween(this._t++, this._b, this._c, this.Duration)));<br/>&nbsp;&nbsp;&nbsp;&nbsp;this._timer = setTimeout(Bind(this, this.Move), this.Time);<br/>&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.MoveTo(this._target);<br/>&nbsp;&nbsp;&nbsp;&nbsp;this.Auto &amp;&amp; (this._timer = setTimeout(Bind(this, this.Next), this.Pause));<br/>&#125;<br/></div><br/>使用說明：<br/>1.html中確認Slider的數量與圖片之寬高<br/>2.SlideTrans.js中改變圖片成現方式的數據<br/><br/>實例化需要3個參數，分別是容器對象，滑動對象和切換數量，之後可以直接執行Run方法運行：<br/>HTML的CSS中找出：<br/><div class="code">.container, .container img&#123;width:199px; height:38px;&#125;</div><br/>HTML的script中找出(<strong>4</strong>為圖片數目)：<br/><div class="code">new SlideTrans(&quot;idContainer&quot;, &quot;idSlider&quot;, 4, &#123; Vertical: false &#125;).Run();<br/></div><br/>SlideTrans.js 中找出：<br/><div class="code">Vertical:&nbsp;&nbsp;true,//是否垂直方向（方向不能改）<br/>Auto:&nbsp;&nbsp;&nbsp;&nbsp;true,//是否自動<br/>Change:&nbsp;&nbsp;&nbsp;&nbsp;0,//改變數<br/>Duration:&nbsp;&nbsp;40,//滑動持續時間<br/>Time:&nbsp;&nbsp;&nbsp;&nbsp;25,//滑動延時<br/>Pause:&nbsp;&nbsp;&nbsp;&nbsp;4000,//停頓時間(Auto為true時有效)<br/>onStart:&nbsp;&nbsp;function()&#123;&#125;,//開始轉換時執行<br/>onFinish:&nbsp;&nbsp;function()&#123;&#125;,//完成轉換時執行<br/>Tween:&nbsp;&nbsp;&nbsp;&nbsp;Tween.Quart.easeOut//tween算子</div><br/>其中Vertical初始化後就不能修改，Tween算子可參照這裡的緩動效果選擇（實例中選了其中3個）。<br/>還有提供了以下方法：<br/>Next:切換下一個<br/>Previous:切換上一個<br/>Stop:停止自動切換<br/>還有上面說到的Run<br/>這個檔案只能在登入之後下載。請先 <a href="https://blog.apao.idv.tw/login.php?job=register">註冊</a> 或 <a href="https://blog.apao.idv.tw/login.php">登入</a><br/>Tags - <a href="https://blog.apao.idv.tw/tags/%25E5%259C%2596%25E7%2589%2587/" rel="tag">圖片</a> , <a href="https://blog.apao.idv.tw/tags/%25E8%2587%25AA%25E5%258B%2595/" rel="tag">自動</a> , <a href="https://blog.apao.idv.tw/tags/%25E6%25BB%2591%25E5%258B%2595/" rel="tag">滑動</a> , <a href="https://blog.apao.idv.tw/tags/%25E5%2588%2587%25E6%258F%259B/" rel="tag">切換</a> , <a href="https://blog.apao.idv.tw/tags/%25E6%2595%2588%25E6%259E%259C/" rel="tag">效果</a> , <a href="https://blog.apao.idv.tw/tags/%2528javascript_slidetrans%2529/" rel="tag">(javascript slidetrans)</a>
]]>
</description>
</item><item>
<link>https://blog.apao.idv.tw/post//#blogcomment</link>
<title><![CDATA[[評論] 圖片自動滑動切換效果 (JavaScript_SlideTrans)]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[評論]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.apao.idv.tw/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>