jQuery 轮播不重复
我正在尝试为我的网站创建一个轮播,但无法将幻灯片移动到列表的后面,因此它是一个连续的流,没有空白。代码如下:
<div class="maskleft"></div>
<div class="maskright"></div>
<div class="slideshow">
<div class="views-row views-row-1 views-row-odd views-row-first">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-2 views-row-even">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-3 views-row-odd">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-4 views-row-even views-row-last">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
</div>
jQuery 是:
function slideChange() {
var $slider = $('.slideshow');
var $next = $slider.next().length ? $slider.next() : $('.slideshow');
$next.animate({marginLeft: '-=1024'}, 1000, function() {
});
}
$(document).ready(function() {
setInterval( "slideChange()", 5000 );
});
实时开发站点在这里:http://dev.shoeboxdesign.co。英国/
I am trying to create a carousel for my site and am having trouble getting the slides to move to the back of the list, so it is a continuous stream with no white space. Here is the code:
<div class="maskleft"></div>
<div class="maskright"></div>
<div class="slideshow">
<div class="views-row views-row-1 views-row-odd views-row-first">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-2 views-row-even">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-3 views-row-odd">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
<div class="views-row views-row-4 views-row-even views-row-last">
<div class="panel-text">text</div>
<div class="views-field views-field-field-image-feature">
<img typeof="foaf:Image" src="" alt="" />
</div>
<img typeof="foaf:Image" src="" alt="" />
</div>
</div>
The jQuery is:
function slideChange() {
var $slider = $('.slideshow');
var $next = $slider.next().length ? $slider.next() : $('.slideshow');
$next.animate({marginLeft: '-=1024'}, 1000, function() {
});
}
$(document).ready(function() {
setInterval( "slideChange()", 5000 );
});
The live dev site is here: http://dev.shoeboxdesign.co.uk/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只有一个正在移动的
div
,为什么需要此代码:当你到达幻灯片结尾:
You have only one
div
whitch is moving, why do you need this code:You need to reset your
marginLeft
style when you reach end of your slideshow:如果我的理解是对的,您希望将第一张幻灯片附加到幻灯片的末尾,这样您就有一个恒定的流,而不是跳回到开头。
假设这是正确的,我们发现了一个重要的关键字:append。
您必须虚拟地拍摄第一张幻灯片并将其附加到最后一张幻灯片。通过每个动画步骤执行此操作。我们最终得到这样的结果。
该解决方案未经测试,但应该可以解决问题。
但我仍然发现您的代码存在一些问题。
您想仅将此功能用于此滑块吗?如果您的答案是“是”,您应该明确为滑块提供
#id
而不是.class
选择器。而且由于您不会再在任何地方使用您的函数,因此不需要可公开访问的函数。您可以匿名进行,这可以节省一些资源。If I get you right, you want to append the first slide to the end of the slideshow so you have a constant stream instead of a jump cut back to the start.
Assuming this is correct, we found an important keyword: append.
You have to virtually take the first slide and append it to the last slide. Do this by every animation step. We end up with something like this.
This solution is untested but should do the trick.
But I still see some problems in your code.
Do you want to use this function only for this slider? If your answer is 'yes' you should definetly give your slider an
#id
and not a.class
selector. And because you won't use your function anywhere again, there's no need for a publicly accessible function. You could make it anonymously, which saves some ressources.