2013-11-05 53 views
0

我有其中包含从数据库项目的变化量DIV停止动态宽度DIV。我已经设置了DIV动画加/减894px从它被点击下一个/上一个按钮时,当前位置。现在我想从过去的动画或0像素过去它是最后一个孩子停下来,但我在努力得到它的工作,而无需使用一个固定的宽度DIV。有谁知道解决方案?由于从动画过去,它的边缘

http://jsfiddle.net/Drennan/mMMfn/

$('#right').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#inner').animate(
        {left:"-=894px"}, { 
         duration:'slow', 
         easing:'swing' 
       }); 
      } 
     ); 
    } 
); 

$('#left').each(
    function(){ 
     $(this).bind (
      "click", 
      function(event){ 
       $('#inner').animate(
        {left:"+=894px"}, { 
         duration:'slow', 
         easing:'swing' 
       }); 
      } 
     ); 
    } 
); 



}); 

回答

1

我一直在你的jsfiddle一点玩耍。

这是你想要做什么? http://jsfiddle.net/2cmNf/

我添加了一个if语句的“next”函数测试是否#inner div的最后一个项目是关于去关闭屏幕。

if ($('#inner').position().left + $('#inner').width() > 294) { //animate it to move left }

else { //do nothing, or maybe you could grey out the next button if there are no more items. Whatever you want. }