JavaScript跑马灯

图片地址:http://download.csdn.net/detail/richard_jason/9665688

效果图:



示例代码:

<!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>js跑马灯</title>
<style type="text/css">
<!--
* {  margin:0 auto; padding:0;border:none;}
body { background-color:#323232;font-size:16px;}
div{overflow:hidden; }
img { border:0; }
.box { width:989px; margin:40px auto 0; background:#fff; border:1px solid #999;}
#demo{width:936px; overflow:hidden;}
#demo img{width:186px; height:160px; margin:15px 10px;}
#demo3 td{text-align:center; margin:5px; width:226px;}
.lanmu{ width:989px; height:32px; background:url(images/jfh/pic1.png) no-repeat;}
.lanmu h3{width:100px; margin-left:35px; line-height:32px; color:#DADADA;}
.lanmu span{ float:right; width:85px; }
.lanmu span a{line-height:32px; color:#DADADA;}
-->
</style>
</head>


<body><div class="box">
<div class="lanmu"><h3>产品展示</h3></div>  
<table>
    <tr>
    <td>
        <img οnmοuseοver="moveThis('left')" style="cursor: pointer"   οnmοusedοwn="goThis('left')"  οnmοuseοut="moveout()"   src="images/jfh/scrollLeft.gif" />
    </td>
    <td>
        <div id="demo">
            <table id="container">
            <tr>
                <td id="demo1">
                    <table id="demo3">
                    <tr>
                    <td><a href="#"><img src="images/jfh/1.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/2.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/3.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/4.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/5.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/6.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/7.jpg" /></a></td>
                    <td><a href="#"><img src="images/jfh/8.jpg" /></a></td>     
                    </tr>
                    </table>
                </td>
            <td id="demo2"></td></tr>
            </table>         
        </div>
    </td>
    <td>
        <img οnmοuseοver="moveThis('right')"   οnmοusedοwn="goThis('right')"    style="cursor: pointer" οnmοuseοut="moveout()"    src="images/jfh/scrollRight.gif"/>
    </td>
    </tr>
</table>
<div class="lanmu"></div>
</div>
</body>
</html>
  <script type="text/javascript" src="js/jfh/js.js" language="javascript"></script>


----------------------------------------------------------------------------------------------------------------


JavaScript代码:


var speed=20;var demo=document.getElementById("demo");var demo1=document.getElementById("demo1");var demo2=document.getElementById("demo2");demo2.innerHTML=demo1.innerHTML;function MarqueeL(){if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth}else{demo.scrollLeft++}};function MarqueeR(){if(demo2.offsetWidth-demo.scrollLeft>=910){demo.scrollLeft+=demo1.offsetWidth}else{demo.scrollLeft--}};function MarqueeLs(){if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth}else{demo.scrollLeft=demo.scrollLeft+5}};function MarqueeRs(){if(demo2.offsetWidth-demo.scrollLeft>=910){demo.scrollLeft+=demo1.offsetWidth}else{demo.scrollLeft=demo.scrollLeft-5}};function MarqueeLss(){if(demo2.offsetWidth-demo.scrollLeft<=0){demo.scrollLeft-=demo1.offsetWidth}else{demo.scrollLeft=demo.scrollLeft+15}};function MarqueeRss(){if(demo2.offsetWidth-demo.scrollLeft>=910){demo.scrollLeft+=demo1.offsetWidth}else{demo.scrollLeft=demo.scrollLeft-15}};var flag=1;var MyMar;demo.οnmοuseοver=function(){if(MyMar){clearInterval(MyMar)}};function moveout(way){if(MyMar){clearInterval(MyMar);moveThis('left')}};function moveThis(way){if(way=='right'){flag=1;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeR,speed)}else{flag=0;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeL,speed)};if(flag){demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeR,speed)}}else{demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeL,speed)}}};function goThis(way){if(way=='right'){flag=1;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeRs,speed)}else{flag=0;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeLs,speed)};if(flag){demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeRs,speed)}}else{demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeLs,speed)}}};function goThisk(way){if(way=='right'){flag=1;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeRss,speed)}else{flag=0;if(MyMar){clearInterval(MyMar)};MyMar=setInterval(MarqueeLss,speed)};if(flag){demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeRss,speed)}}else{demo.οnmοuseοut=function(){MyMar=setInterval(MarqueeLss,speed)}}};moveThis('left');



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值