您的位置:首页 > Web前端 > CSS

CSS滚动图片制作技巧

2012-12-06 16:32 176 查看
拷贝到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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: