图片减速度滚动(by rentj1@163.com;) 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[名前] = val;
},
get: function(id){
document.getElementById(id)
}
}
function ScrollSlider(container, content){
var clone = content .cloneNode(true);
var initcss= "左:0; 上:0";
var contentHeight = content.offsetHeight;
var コンテナ高さ = コンテナ.クライアント高さ;
clone.id = "コンテンツクローン";
container.appendChild(クローン);
clone.setAttribute("cssText", initcss);
content.setAttribute("cssText", initcss);
clone.style.marginTop = contentHeight "px";
this.content = コンテンツ;
this.clone = クローン;
this.container = コンテナ;
this.containerHeight = コンテナ高さ;
this.contentHeight = contentHeight;
}
ScrollSlider.prototype = {
start: function(lay){
var _this = this;
clearInterval(_this.timer);
_this.timer = setInterval(function(){
_this.scroll();
},lay);
},
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 速度 = (s-s1)/8;
speed = 速度 > 0 ? Math.ceil(speed) : Math.floor(speed);
s1 = 速度;
m = marginTop - s1;
untils.setStyle(_this.content, "marginTop"); ", (m offsetTop) "px");
if(s-s1 clearInterval(timer);
}
},30);
}
};
varcontainer = 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,-164,-328,164 ,0
328,164,0,-164,-328,164,0
*/