实现公告栏⽆缝滚动的js代码(转)<!DOCTYPE HTML>
<html>
<head>
<meta charset="gb2312"/>
<title></title>
<style>
ul {
margin:100px;
height:22px;
border:1px solid red;
overflow:hidden;
}
li {
height:22px; line-height:22px; font-size:12px;
}
</style>
</head>
<body>
<ul id="a">
<li>1-1</li>
<li>1-2</li>
<li>1-3</li>
<li>1-4</li>
</ul>
<script>
//ElementById()的最简化应⽤
function $(element){
if(arguments.length>1){
for(var i=0,length=arguments.length,elements=[];i<length;i++){
elements.push($(arguments[i]));
}
return elements;
}
if(typeof element=="string"){
ElementById(element);
}else{
return element;
}
}
//类创建函数
var Class={
create:function(){
return function(){
this.initialize.apply(this,arguments);
}
}
}
//对象属性⽅法扩展
Function.prototype.bind=function(object){
var method=this;
return function(){
method.apply(object,arguments);
}
}
var ate();
Scroll.prototype={
//第⼀个参数定义要滚动的区域,第⼆个参数定义每次滚动的⾼度
initialize:function(element,height,delay){
this.element=$(element);
this.element.innerHTML+=this.element.innerHTML;
this.height=height;
this.delay=delay*1000;
this.maxHeight=this.element.scrollHeight/2;
this.scroll();
this.timer="";
useover=this.stop.bind(this);
useout=function(){this.timer=setTimeout(this.scroll.bind(this),1000);}.bind(this);
},
scroll:function(){
if(this.element.scrollTop<this.maxHeight){
this.element.scrollTop++;
}else{
this.element.scrollTop=0;
}
unter<this.height){
this.timer=setTimeout(this.scroll.bind(this),5);
}else{
this.timer=setTimeout(this.scroll.bind(this),this.delay); }
},html自动弹出公告代码
stop:function(){
clearTimeout(this.timer);
}
}
new Scroll('a', 22, 2)
</script>
</body>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论