图片减速度滚动(by rentj1@163.com;)
<스크립트>
untils = {
getComputeStyle: function(elem,syle){
var ComputedStyle = document.defaultView
&& document.defaultView.getComputeStyle
&& document.defaultView.getCompulatedStyle(elem,null) ;
if(!computedStyle){
computedStyle = elem.currentStyle
}
return ComputedStyle[syle]
},
setStyle: function(elem, name,val){
elem.style[이름] = 발;
},
get: function(id){
document.getElementById(id)
}
}
function ScrollSlider(container, content){
var clone = content .cloneNode(참);
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(delay){
var _this = this;
clearInterval(_this.timer);
_this.timer = setInterval(function(){
_this.scroll();
},delay);
},
scroll: function(){
var marginTop =parseInt(untils.getCompulatedStyle(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);
},
이동: 함수(marginTop, offsetTop){
var s = this.containerHeight, s1 = 0, _this = this, m = 0;
var 타이머 = setInterval(function(){
var 속도 = (s-s1)/8;
speed = 속도 > 0 ? Math.ceil(speed) : Math.floor(speed);
s1 = 속도;
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 컨테이너 = document.getElementById("컨테이너")
var content = document.getElementById("content")
var xx = new ScrollSlider(컨테이너, 컨텐츠);
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
*/