代码如下:
图片减速度滚动(by rentj1@163.com;)
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
兵尼兔 环保大包围专车专用脚垫 米色(专车专用,仅支持在线支付)版型精准 大包围
会员价:¥288.00
untils = {
getComputedStyle: function(elem,syle){
var computedStyle = document.defaultView
&& document.defaultView.getComputedStyle
&& document.defaultView.getComputedStyle(elem,null);
if(!computedStyle){
computedStyle = elem.currentStyle
}
return computedStyle[syle]
},
setStyle: function(elem, name,val){
elem.style[name] = val;
},
get: function(id){
document.getElementById(id)
}
}
function ScrollSlider(container, content){
var clone = content.cloneNode(true);
var initcss= "left:0; top:0";
var contentHeight = content.offsetHeight;
var containerHeight = container.clientHeight;
clone.id = "content-clone";
container.appendChild(clone);
clone.setAttribute("cssText", initcss);
content.setAttribute("cssText", initcss);
clone.style.marginTop = contentHeight+"px";
this.content = content;
this.clone = clone;
this.container = container;
this.containerHeight = containerHeight;
this.contentHeight = contentHeight;
}
ScrollSlider.prototype = {
start: function(delay){
var _this = this;
clearInterval(_this.timer);
_this.timer = setInterval(function(){
_this.scroll();
},delay);
},
scroll: function(){
var marginTop = parseInt(untils.getComputedStyle(this.content, "marginTop"));
var offsetTop = this.contentHeight;
if(isNaN(marginTop))return;
if( -marginTop >= this.contentHeight){
marginTop = this.contentHeight;
}
if(marginTop > 0){
offsetTop = -offsetTop;
}
this.move(marginTop, offsetTop);
},
move: function(marginTop, offsetTop){
var s = this.containerHeight, s1 = 0, _this = this, m = 0;
var timer = setInterval(function(){
var speed = (s-s1)/8;
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
s1 += speed;
m = marginTop - s1;
untils.setStyle(_this.content, "marginTop", m + "px");
untils.setStyle(_this.clone, "marginTop", (m + offsetTop)+"px");
if(s-s1 <= 0){
clearInterval(timer);
}
},30);
}
};
var container = document.getElementById("container")
var content = document.getElementById("content")
var xx = new ScrollSlider(container, content);
xx.start(1000*3);
/*
//s=1/2 * at^2
//s (att)/2
//0
0,-1,-328,1,0
328,1,0,-1,-328,1,0
*/
script>