CSS滚动图片制作技巧

拷贝到dreamweaver查看效果

新闻网图片滚动

ul.picNews_list { padding:0; margin:5px 0}
ul.picNews_list li{ float:left; text-align:center; width:160px; height:150px}
ul.picNews_list li img{width:150px; height:120px; border:0; padding-bottom:5px;}/*<li><a><img ><br>题目</a></li>*/
ul.picNews_list li a,{color:#1f376d}
ul.picNews_list li a:hover{color:#039}

实例

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>向上无缝滚动的封装的演示</title>
<style type="text/css">
<!--
ol,ul{list-style:none; margin:0;padding:0}
li{ height:25px}
#demo3 ul,#demo4 ul{float:left; width:400px; background-color:#996600}
#demo3 li,#demo4 li{ float:left; width:50px}
-->
</style>
</head>
<body>
<p>这个是速度为10的滚动</p>
<div id="demo" style=" overflow: hidden; width: 322px; height: 50px">
<ul>
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
<li>666</li>
<li>777</li>
<li>888</li>
</ul>
</div>
<hr />
<p>这个是速度为50的向下滚动</p>
<div id="demo2"  style=" overflow: hidden; width: 322px; height: 50px; background-color:#993300"><!--height:50px;的高度要小于,下面ul的整体高度,才能滚动-->
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
<li>ddd</li>
<li>eee</li>
<li>fff</li>
<li>ggg</li>
<li>hhh</li>
</ul>
</div>
<hr />
<p>这个是速度为10的向左滚动</p>
<div id="demo3" style="overflow: hidden; width: 300px; height: 25px"> <!--width的宽300px度必须小于 ul的宽度400px,才能滚动-->
<ul>
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
<li>555</li>
<li>666</li>
<li>777</li>
<li>888</li>
</ul>
</div>
<hr />
<p>这个是速度为50的向右滚动</p>
<div id="demo4" style="overflow: hidden; width: 200px; height: 25px">
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
<li>ddd</li>
<li>eee</li>
<li>fff</li>
<li>ggg</li>
<li>hhh</li>
</ul>
</div>
<script type="text/javascript">
function next(elem){
do{
elem=elem.nextSibling;
}while(elem&&elem.nodeType!=1);
return elem;
}
//---查找第一个子元素的函数---//
function first(elem){
elem=elem.firstChild;
return elem && elem.nodeType!=1?next(elem):elem;
}

var Marquee = {
init : function(id,toFollow,speed){
this.speed = speed || 10;
this.boxID = id;
this.toFollow=toFollow;
this.scrollBox = document.getElementById(id);

if(this.toFollow=="top"||this.toFollow=="bottom"){
this.appendBox=first(this.scrollBox).cloneNode(true);
this.scrollBox.appendChild(this.appendBox);
}else{
var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>"+this.scrollBox.innerHTML+"</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>"+this.scrollBox.innerHTML+"</td></tr></table>";
this.scrollBox.innerHTML=templateLeft;
this.appendBox=first(first(first(first(this.scrollBox))));

}
this.objs = {
scrollBox : this.scrollBox,
appendBox : this.appendBox,
toFollow : this.toFollow,
speed : this.speed,
id : this.boxID
};
return this;
},

scrollUp : function(){
var self = this.objs;
self.begin = function(){

if(self['toFollow']=="top"){
self.doScr = setInterval(function(){
if(self['appendBox'].offsetHeight<=self['scrollBox'].scrollTop){
self['scrollBox'].scrollTop-=first(self['scrollBox']).offsetHeight;
}else{
self['scrollBox'].scrollTop++;
}
},self.speed);
}else if(self['toFollow']=="bottom"){
self.doScr = setInterval(function(){
if(self['scrollBox'].scrollTop<=0){
self['scrollBox'].scrollTop=self['appendBox'].offsetHeight;
}else{
self['scrollBox'].scrollTop--;
}
},self.speed);
}else if(self['toFollow']=="left"){
self.doScr = setInterval(function(){
if(self['appendBox'].offsetWidth<=self['scrollBox'].scrollLeft){
self['scrollBox'].scrollLeft-=self['appendBox'].offsetWidth;
}else{
self['scrollBox'].scrollLeft++;
}
},self.speed);
}else if(self['toFollow']=="right"){
self.doScr = setInterval(function(){
if(self['scrollBox'].scrollLeft<=0){
self['scrollBox'].scrollLeft=self['appendBox'].offsetWidth;
}else{
self['scrollBox'].scrollLeft--;
}

},self.speed);

}
}
self.begin();
self.scrollBox.onmouseover = function(){
clearInterval(self.doScr);
}

self.scrollBox.onmouseout = function(){
self.begin();
}
}

}

Marquee.init("demo","top").scrollUp(); 
Marquee.init("demo2","bottom", 50).scrollUp();
Marquee.init("demo3","left").scrollUp();
Marquee.init("demo4","right", 50).scrollUp();
</script>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值