2011-02-09 16 views
0

JQueryを使用した垂直スライドショーを実装したいと思います。私は垂直リール(div)を使用しています。イメージを1つずつ順番に表示しています。リールを減らしています。イメージサイズで2秒ごとにトップポジションが動作していますが、最後のイメージに到達すると、第1の画像からリールを開始するロジック。私の説明が明確でない場合、私は私のコードを付加しています:JQueryスライドショーのロジック

<script type="text/javascript"> 
    $(function() { 
     setInterval(SlideImage, 2000); 
    }); 

    function SlideImage() { 
     $("#imgReel").animate({ "marginTop": "-=300px" }, 1000, function() { }); 
    } 
</script> 

<style type="text/css"> 
    img 
    { 
     width: 600px; 
     height: 300px; 
    } 
    .imgContainer 
    { 
     overflow: hidden; 
     width: 620px !important; 
     height: 300px !important; 
    } 
    div 
    { 
     width: 620px; 
    } 
    .current 
    { 
     z-index: 0; 
    } 
    .next 
    { 
     z-index: 1; 
    } 
    .imgReel 
    { 
     width: 620px !important; 
    } 
    . 
</style> 

<body> 
<div id="imgContainer" class="imgContainer"> 
    <div id="imgReel" class="imgReel"> 
     <div class="current"> 
      <img src="Images/Summerwave.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Sunlight_and_the_Wild_Forest_Floor.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Sunset.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Swimming_with_the_fishys.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Tearing_Apart.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Teaser.jpg" /> 
     </div> 
     <div> 
      <img src="Images/Terra_Nova.jpg" /> 
     </div> 
    </div> 
</div> 

をすべてのヘルプは大幅に

答えて

1

あなたは他のアプローチを使用することができます。#imgReelは固定させ、および要素のサイズを変更:

が下にimgReelを移動する、この最初の要素の前に追加、あなたが一番上の要素にslideUpをすればということになります一番下(最後の要素の後)に、リールが動いているという効果があり、現在の画像の上端が最初に消えます。プラグインscrollTo使用してコードで

、:scrollToを使用して、あなたが無限ループを作りたくない場合は、一方

var $reel = null; 
function init() { 
    $reel = $("#imgReel") 
    // Keep the first element as first shown, now that we're going to take the reel to the bottom 
    $reel.children("div:first").insertAfter($reel.children("div:last")) 
    // Move to the bottom using scrollTo or whatever you want: 
    $reel.scrollTo("max") 
} 

function next() { 
    // Clone the first element (not visible) at the end 
    var $topElement = $reel.children("div:first") 
    var $bottomElement = $topElement.clone().appendTo($reel) 

    // Hide the top element (cloned now at the bottom) and remove it when it's done 
    $topElement.slideUp(1000, function() { $(this).remove() }) 

    // Mark the next 'current' 
    $reel.children(".current").removeClass("current"); 
    $bottomElement.addClass("current"); 
} 

を、そしてあなたのアプローチを維持するには、このように簡単です:

funnction next() { 
    var $current = $reel.find("div.current").removeClass("current") 
    var $next = $current.next() 
    if(!$next.length) $next = $reel.children("div:first") 
    $reel.scrollTo($next.addClass("current"), 1000) 
} 

function prev() { 
    var $current = $reel.find("div.current").removeClass("current") 
    var $next = $current.prev() 
    if(!$next.length) $next = $reel.children("div:last") 
    $reel.scrollTo($next.addClass("current"), 1000) 
}) 

希望する:-)

0

をいただければ幸いあなたは背中の上部に移動しますか、リール、または移動してくださいdivリールの最後に表示されます。

最初に戻って、ボックスをある色にフェードアウトさせて、最初に移動して(ユーザーはこの現象は見られません)、色を消してください。このようにして、ユーザは彼が同じ絵を再び見ていることを知る。

関連する問題