JS特效——图片水平滚动

具体源码如下:

<!doctype html>
<html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />            
        <meta name="keywords" content="关键字1,关键字2" />        
        <meta name="Description" content="描述信息" />
        <title>水平循环滚动</title>
        <!--CSS/JS-->
        <style type="text/css">
            *{margin:0;padding:0;}
            ul,li{list-style:none;display:block;}
            #scrollBox{background: #FFF;margin:40px auto;overflow:hidden;border: 1px dashed #CCC;width: 500px;}
            #scrollBox #con1,#scrollBox #con2{float:left;margin-left:10px;}        
            #innerdiv {float: left;width: 800%;}
            
        </style>
        
        
    </head>
 <body>
        <!--div-->
    <div id="scrollBox">
        <div id="innerdiv">
            <div id="con1">
                <a href="#"><img src="1.jpg" height="120" width="192"></a>
                <a href="#"><img src="2.jpg" height="120" width="192"></a>
                <a href="#"><img src="3.jpg" height="120" width="192"></a>
                <a href="#"><img src="4.jpg" height="120" width="192"></a>
                <a href="#"><img src="5.jpg" height="120" width="192"></a>
                <a href="#"><img src="6.jpg" height="120" width="192"></a>
                <a href="#"><img src="7.jpg" height="120" width="192"></a>
                <a href="#"><img src="8.jpg" height="120" width="192"></a>
                <a href="#"><img src="9.jpg" height="120" width="192"></a>
            </div>
            <div id="con2"></div>
        </div>
    </div>
    <script type="text/javascript">            
                var area =document.getElementById('scrollBox');
                var con1 = document.getElementById('con1');
                var con2 = document.getElementById('con2');
                con2.innerHTML=con1.innerHTML;
                 area.scrollLeft=0;                 
               function scrollUp(){
                if(area.scrollLeft>=con2.offsetWidth){
                    area.scrollLeft=0;
                }else{
                    area.scrollLeft+=5;
                }
                }                
                var time = 50;
                var mytimer=setInterval(scrollUp,time);
                area.onmouseover=function(){
                    clearInterval(mytimer);
                }
                area.onmouseout=function(){
                    mytimer=setInterval(scrollUp,time);
                }
                /*
                var speed=10; //数字越大速度越慢
                var tab=document.getElementById('scrollBox');
                var tab1=document.getElementById('con1');
                var tab2=document.getElementById('con2');
                tab2.innerHTML=tab1.innerHTML;
                function Marquee(){
                if(tab2.offsetWidth-tab.scrollLeft<=0)
                tab.scrollLeft-=tab1.offsetWidth
                else{
                tab.scrollLeft++;
                }
                }
                var MyMar=setInterval(Marquee,speed);
                tab.οnmοuseοver=function() {clearInterval(MyMar)};
                tab.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)};
                */

        </script>
 </body>
 
</html>

效果预览:GitHub

转载于:https://www.cnblogs.com/caoleiCoding/p/6164212.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值