• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

js实现图片上下滚动:js实现文字定时上下_js

javascript 搞代码 7年前 (2018-06-13) 175次浏览 已收录 0个评论

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="文字定时上下滚动效果" />
<title>兼容多种浏览器的文字定时上下滚动效果</title>
<style type="text/css">
.cls_container {
border: 1px solid #ccc;
width: 380px;
font-size: 12px;
height: 24px;
overflow: hidden;
}
.cls_container ul {
list-style-type: none;
margin: 0;
padding: 0;
margin-left: 32px;
}
.cls_container ul li {
height: 24px;
line-height: 24px;
width: 320px;
float: left;
display: inline;
}
</style>
</head>
<body>
<div id="myscroll" class="cls_container">
<ul>
<li><a href="http://www.cxybl.com/">LI文字效果1</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果2</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果3</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果4</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果5</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果6 </a></li>
<li><a href="http://www.cxybl.com/">LI文字效果7</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果8</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果9</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果10</a></li&gt;
<li><a href="http://www.cxybl.com/">LI文字效果11</a></li&gt;
</ul>
</div>
<script type="text/JavaScript">
function $(element){
if(arguments.length>1){//如果有多个目标对象,则循环将所有目标对象都存于elements数组当中
for(var i=0,length=arguments.length,elements=[];i<length;i++){
elements.push($(arguments[i]));
}
return elements;
}
if(typeof element=="string"){//如果是一个目标ID,则取对应的dom对象
return document.getElementById(element);
}else{//如果是一个dom对象,直接返回
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 Scroll=Class.create();
Scroll.prototype={
initialize:function(element,height){
this.element=$(element);
this.element.innerHTML+=this.element.innerHTML;
this.height=height;
this.maxHeight=this.element.scrollHeight/2;
this.counter=0;
this.scroll();
this.timer="";
this.element.onmouseover=this.stop.bind(this);
this.element.onmouseout=function(){
this.timer=setTimeout(this.scroll.bind(this),1000);
}.bind(this);
},
scroll:function(){
if(this.element.scrollTop<this.maxHeight){
this.element.scrollTop++;
this.counter++;
}else{
this.element.scrollTop=0;
this.counter=0;
}
if(this.counter<this.height){
this.timer=setTimeout(this.scroll.bind(this),20);
}else{
this.counter=0;
this.timer=setTimeout(this.scroll.bind(this),3000);
}
},
stop:function(){
clearTimeout(this.timer);
}
}
//调用函数进行文字滚动效果
new Scroll("myscroll",24);
</script>
</body>
</html>
 
本文链接http://www.cxybl.com/html/wyzz/javaScript_Ajax/20121228/35283.html

欢迎大家阅读js实现图片上下滚动:js实现文字定时上下…_js》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:js实现图片上下滚动:js实现文字定时上下_js
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址