2017-03-21 47 views
1

我建立了一個最小傳送帶,當有3張或更多張幻燈片時,似乎可以正常工作,但是一旦我移除某些幻燈片,事情就會開始中斷。有些事情我發現是:當有3張或更多幻燈片時,傳送帶工作,但只有2張幻燈片時傳送帶打開

  1. 它消除了對滑動動畫「下一步」
  2. 它會讓我的div閃爍
  3. 這將打破動畫完全

我曾在一些可能的在第一張幻燈片上處理.clone()的解決方案,然後在容器的末端使用.append(),這使得它有點工作,但它通常只會進行1次旋轉,然後卡在slide2上。

這裏是我的邏輯來處理一下上一個/下一個按鈕

var before_clone = $(elm + ':first').clone(); 
var after_clone = $(elm + ':last').clone(); 
$('#buttons a').click(function(e) { 
    //slide the item 
    if (container.is(':animated')) { 
     return false; 
    } 
    if (e.target.id == previous) { 
     container.stop().animate({ 
      'left': 0 
     }, 1500, function() { 
      //container.find(elm + ':first').before(container.find(elm + ':last')); 
      container.append(after_clone); 
      container.find(elm + ':last'); 
      resetSlides(); 
     }); 
    } 
    if (e.target.id == next) { 
     container.stop().animate({ 
      'left': item_width * -1 
     }, 1500, function() { 
      //container.find(elm + ':last').after(container.find(elm + ':first')); 
      container.append(before_clone); 
      container.find(elm + ':first'); 
      resetSlides(); 
     }); 
    } 
    //cancel the link behavior    
    return false; 
}); 

,這裏是我的邏輯處理自動動畫

function rotate() { 
    $('#next').click(); 
     container.append(before_clone); 
     container.append(after_clone) 
} 

這裏有兩個小提琴以及幫助診斷我的問題

my current attempt

my original code(make sure to remove/comment out 2 of the lis)

感謝任何幫助,您可以提供解決這個! 謝謝!

回答

1

看看this小提琴。

我改變了你的next以下幾點:

if (e.target.id == next) { 
    container.find(elm + ':last').after(container.find(elm + ':first')); 
    container.css({ 
     'left': 0 
    }); 
    container.stop().animate({ 
     'left': item_width * -1 
    }, 1500, function() { 
     resetSlides(); 
    }); 
    } 
+0

嗯,我會被定罪。非常感謝您的幫助,這非常完美! –

相關問題