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>
新闻网图片滚动
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>
相关文章推荐
- CSS网页制作技巧:背景图片定位 显示切图的一部分作为背景显示
- CSS网页制作技巧:图片的自适应居中和兼容处理(转)
- CSS网页制作技巧:背景图片定位
- 详解CSS制作Web页面条纹背景样式的技巧
- 制作一幅扑克牌系列二---不用图片的纯css实现方法
- Jquery+css实现图片无缝滚动轮播
- 网站制作技术分享--批量下载CSS中的图片
- CSS技巧 — 不使用图片实现圆角、阴影、渐变等功能
- css技巧—图片配文字
- PPT中滚动字幕的制作及与音乐同步的技巧
- Web标准化制作:利用CSS按比例缩小图片
- 化图片为CSS页面的独门技巧
- JQUERY制作图片滚动
- CSS高级技巧:图片替换
- jQuery+CSS实现的图片滚动效果
- 按钮制作技巧(css精灵效果)-高级版
- css 实现背景图片不跟着滚动条滚动而滚动
- CSS实战技巧:清除图片3pxbug
- CSS制作图片水平垂直居中
- 【转】CSS高级技巧:图片替换