圖片滾動經(jīng)常在網(wǎng)頁里面用到,高手們都是自己來寫,我不是高手,所以高手們寫了,我就搬來用了,偷偷懶,“常用js效果一:div+css圖片上下左右滾動代碼”這個也是在網(wǎng)上找的,這個被轉(zhuǎn)載了很多次,測試了下,ie6,7,8還有火狐都能兼容的。還有demo哦??!需要的可以下載哈。
這是向上滾動的:
XML/HTML代碼 - <style type="text/css">
- <!--
- #demo {
- background: #FFF;
- overflow:hidden;
- border: 1px dashed #CCC;
- height: 300px;
- text-align: center;
- float: left;
- }
- #demo img {
- border: 3px solid #F2F2F2;
- display: block;
- }
- -->
- </style>
- 向上滾動
- <div id="demo">
- <div id="demo1">
- <a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>
- </div>
- <div id="demo2"></div>
- </div>
- <script>
- <!--
- var speed=10; //數(shù)字越大速度越慢
- var tab=document.getElementById("demo");
- var tab1=document.getElementById("demo1");
- var tab2=document.getElementById("demo2");
- tab2.innerHTML=tab1.innerHTML; //克隆demo1為demo2
- function Marquee(){
- if(tab2.offsetTop-tab.scrollTop<=0)//當(dāng)滾動至demo1與demo2交界時
- tab.scrollTop-=tab1.offsetHeight //demo跳到最頂端
- else{
- tab.scrollTop++
- }
- }
- var MyMar=setInterval(Marquee,speed);
- tab.onmouseover=function() {clearInterval(MyMar)};//鼠標移上時清除定時器達到滾動停止的目的
- tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠標移開時重設(shè)定時器
- -->
- </script>
演示地址:http://www./demo/1.html
這是向下滾動的: XML/HTML代碼 - <style type="text/css">
- <!--
- #demo {
- background: #FFF;
- overflow:hidden;
- border: 1px dashed #CCC;
- height: 200px;
- text-align: center;
- float: left;
- }
- #demo img {
- border: 3px solid #F2F2F2;
- display: block;
- }
- -->
- </style>
- 向下滾動
- <div id="demo">
- <div id="demo1">
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- </div>
- <div id="demo2"></div>
- </div>
- <script>
- <!--
- var speed=10; //數(shù)字越大速度越慢
- var tab=document.getElementById("demo");
- var tab1=document.getElementById("demo1");
- var tab2=document.getElementById("demo2");
- tab2.innerHTML=tab1.innerHTML; //克隆demo1為demo2
- tabtab.scrollTop=tab.scrollHeight
- function Marquee(){
- if(tab1.offsetTop-tab.scrollTop>=0)//當(dāng)滾動至demo1與demo2交界時
- tab.scrollTop+=tab2.offsetHeight //demo跳到最頂端
- else{
- tab.scrollTop--
- }
- }
- var MyMar=setInterval(Marquee,speed);
- tab.onmouseover=function() {clearInterval(MyMar)};//鼠標移上時清除定時器達到滾動停止的目的
- tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠標移開時重設(shè)定時器
- -->
- </script>
演示地址:http://www./demo/3.html 這是向左滾動的: XML/HTML代碼 - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www./1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>無標題文檔</title>
- </head>
- <body>
- <style>
- .scroll_div {width:600px; height:62px;margin:0 auto; overflow: hidden; white-space: nowrap; background:#ffffff;}
- .scroll_div img {width:120px;height:60px;border: 0;margin: auto 8px; border:1px #efefef solid;}
- #scroll_begin, #scroll_end, #scroll_begin ul, #scroll_end ul, #scroll_begin ul li, #scroll_end ul li{display:inline;}
- </style>
- <script language="javascript">
- function ScrollImgLeft(){
- var speed=20
- var scroll_begin = document.getElementById("scroll_begin");
- var scroll_end = document.getElementById("scroll_end");
- var scroll_div = document.getElementById("scroll_div");
- scroll_end.innerHTML=scroll_begin.innerHTML
- function Marquee(){
- if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0)
- scroll_div.scrollLeft-=scroll_begin.offsetWidth
- else
- scroll_div.scrollLeft++
- }
- var MyMar=setInterval(Marquee,speed)
- scroll_div.onmouseover=function() {clearInterval(MyMar)}
- scroll_div.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
- }
- </script>
- <h2 align="center">向左滾動</h2>
- <div style="text-align:center">
- <div class="sqBorder">
- <!--#####滾動區(qū)域#####-->
- <div id="scroll_div" class="scroll_div">
- <div id="scroll_begin">
- <ul>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- <li><a href="upload/2011/11/201111111446056115.gif" /></a></li>
- </ul>
- </div>
- <div id="scroll_end"></div>
- </div>
- <!--#####滾動區(qū)域#####-->
- </div>
- <script type="text/javascript">ScrollImgLeft();</script>
- </div>
- <!--//向左滾動代碼結(jié)束-->
- </body></html>
演示地址:http://www./demo/2.html 這是向右滾動的代碼: XML/HTML代碼 - <style type="text/css">
- <!--
- #demo {
- background: #FFF;
- overflow:hidden;
- border: 1px dashed #CCC;
- width: 500px;
- }
- #demo img {
- border: 3px solid #F2F2F2;
- }
- #indemo {
- float: left;
- width: 800%;
- }
- #demo1 {
- float: left;
- }
- #demo2 {
- float: left;
- }
- -->
- </style>
- 向右滾動
- <div id="demo">
- <div id="indemo">
- <div id="demo1">
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- <a href="#"><img src="upload/2011/11/201111141335356083.gif" border="0" /></a>
- </div>
- <div id="demo2"></div>
- </div>
- </div>
- <script>
- <!--
- var speed=10; //數(shù)字越大速度越慢
- var tab=document.getElementById("demo");
- var tab1=document.getElementById("demo1");
- var tab2=document.getElementById("demo2");
- tab2.innerHTML=tab1.innerHTML;
- function Marquee(){
- if(tab.scrollLeft<=0)
- tab.scrollLeft+=tab2.offsetWidth
- else{
- tab.scrollLeft--
- }
- }
- var MyMar=setInterval(Marquee,speed);
- tab.onmouseover=function() {clearInterval(MyMar)};
- tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};
- -->
- </script>
|