你基本上需要复制的图片放到你的货柜,使得宽度两倍最初。之后,您应该滚动容器,以便当一组图像完全隐藏时,透明地重置容器位置。
下面是代码:
//remove js-disabled class
...
//create new container for images
...
//add images to container
...
// Duplicate container contents
var container = $("div#container");
container.html(container.html() + container.html()) ;
container.width(2 * container.width()) ;
//work out duration of anim based on number of images (1 second for each image)
...
//store speed for later (distance/time)
...
//set direction
...
//set initial position and class based on direction
...
功能:
var el = $("div#container") ;
var parent = el.parent();
var margins = parseInt(parent.css('padding-left'),10) + parseInt(parent.css('padding-right'),10)
+ parseInt(el.css('margin-left'),10) + parseInt(el.css('margin-right'),10)
+ parseInt(el.css('padding-left'),10) + parseInt(el.css('padding-right'),10)
//animator function
var animator = function(el, time, dir) {
//which direction to scroll
if(dir == "rtl") {
var parent = el.parent();
var limit = parent.width() - el.width() + margins ;
//add direction class
el.removeClass("ltr").addClass("rtl");
//animate the el
el.animate({ left: limit+"px" }, time, "linear", function() {
//reset container position
$(this).css({ left:(parent.width()-el.width()/2), right:"" });
//restart animation
animator($(this), duration/2, "rtl");
//hide controls if visible
($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;
});
} else {
var parent = el.parent();
var limit = 0 - margins ;
//add direction class
el.removeClass("rtl").addClass("ltr");
//animate the el
el.animate({ left: -limit + "px" }, time, "linear", function() {
//reset container position
$(this).css({ left:(-el.width()/2), right:"" });
//restart animation
animator($(this), duration/2, "ltr");
//hide controls if visible
($("div#controls").length > 0) ? $("div#controls").slideUp("slow").remove() : null ;
});
}
}
什么联系呢? .... – 2010-12-20 02:32:45
我添加了链接 – dotnetrocks 2010-12-20 02:41:20
教程创建此:http://net.tutsplus.com/tutorials/javascript-ajax/building-a-jquery-image-scroller/ – 2010-12-20 04:42:21