2012-01-17 74 views
1

我创建了jQuery滑块,当我单击下一个箭头时,它将滑动下一个图像。现在我需要持续显示它(即)如果达到滑块中的最后一个图像。然后,第一张图片应从右侧滚动。为此,我试着jquery追加。它正在追加。但是,当我打印位置时,它显示旧位置,而不是附加位置。在jQuery中连续滚动div

<div id="parent"> 
<div class="child"> 
</div> 
<div class="child"> 
</div> 
<div class="child"> 
</div> 
<div class="child"> 
</div> 
</div> 
(i.e)//jQuery 
numberOfSlides = 4; //Total no of images 
$('arrow').click(function(){ 
if(currentSlide == 2) //if i am in the second slide, then append first slide to the last slide 
{ 
    $('first-child').append('parent'); // This code is for reference. not in correct syntax. 
} 
else 
{ 
    for()//loop 
    { 
    //sliding all images to the left (i.e)if the image width is 800px. then the slide animation will be -800,0,800,1600 for(slide1,slide2,slide3,slide4).so that second image will show now. 
    $('.child:nth-child('+loop_count+')').animate({'marginLeft','xxpx'}); 
    } 
} 
currentSlide++; 
}); 

正确O/P时currentSlide 2是-800,0,800,1600为(滑件,滑件3,slide4,滑件1) 在如果条件将追加到父元素的第一个元素上面的代码。但是当我得到附加元素的位置时,它会打印一些-1600像素(当我检查萤火虫时,它显示右侧的div)。但它应该是1600px;我正在使用marginLeft进行定位。

感谢

回答

1

http://archive.plugins.jquery.com/project/aautoscroll

你需要复制你的内容元素,并对准他们,使他们上下彼此相邻,并串联滚动它们。您当前的滚动应该可以工作,跳跃将不可见,因为它应该从底部元素的顶部跳到顶部元素的顶部,也就是说,跳转到相同的部分。我会将两个内容副本(您可以将其克隆到另一个副本)放入容器中并滚动,这样您就不必担心移动两个元素。

如果您想真正优化它,您只能在底部元素中显示内容的顶部(足以隐藏跳转),但除非您的内容非常复杂和繁重,否则不值得付出努力。