js-大图滚动

 

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>大图滚动</title>

	<style>
		.box{
			position:  relative;
			width: 9999px;
		}
		.box img{
			float: left;
			width: 200px;

		}
		.show{
			width: 600px;
			overflow: hidden;
			margin: auto;
		}
		.left,.right{
			overflow: hidden;
			float: left;
		}
        .btn .btn_l{
             float:left;
            width: 50px;
            height: 30px;
            border-radius: 5px;
             border: 1px solid;
             font-size: 16px;
             text-align: center;
             line-height: 30px;
             margin-right: 10px;
             background: red;
        }
        .btn{

            width: 150px;
            height: 51px;
            margin: 10px auto;
        }
        .btn .btn_r{
             float:left;
            width: 50px;
            height: 30px;
            border-radius: 5px;
            border: 1px solid;
             font-size: 16px;
             text-align: center;
             line-height: 30px;
             background: green;
        }
	</style>
</head>
<body>
    <!-- 可视区域 -->
	<div class="show" id="show">
        
		<div class="box" id="box">
            <!-- 向左移动的图片 -->
			<div class="left">
				<img src="image/1.jpg" alt="">
				<img src="image/2.jpg" alt="">
				<img src="image/3.jpg" alt="">
				<img src="image/4.jpg" alt="">
				<img src="image/5.jpg" alt="">
                <!-- 向右移动的图片 -->
			</div><div class="right">
				<img src="image/1.jpg" alt="">
				<img src="image/2.jpg" alt="">
				<img src="image/3.jpg" alt="">
				<img src="image/4.jpg" alt="">
				<img src="image/5.jpg" alt="">
			</div>
		</div>
	</div>
    <div class="btn" id="btn">
        <span class="btn_l">left</span>
        <span class="btn_r">right</span>
    </div>
</body>
	<script>
	var box = document.getElementById('box');
     var btn = document.getElementById('btn').getElementsByTagName('span');
     var show = document.getElementById('show');
	var _index = 0;
    var _bl= true;
    var c = -1;
	var Ti = setInterval('move(_bl)',5);
    var Ti2;
     function move(bl){
            if(bl){
                _index -=2;
               if(_index  <= -1000){
                _index=0;
            } 
           
        }else{
            _index +=2;
             if(_index >= 0){
                _index=-1000;
            }
        }

           
         
         if(_index % 200 == 0){
            //清除对象
             clearInterval(Ti);
             Ti2 = setTimeout(function(){
                Ti = setInterval('move(_bl)',5);
            }, 1000);
         }
          box.style.left = _index + 'px';
            }
        btn[0].onclick = function(){
             _bl = true;   
        } 
        btn[1].onclick = function(){
            _bl = false;
        }
        //  鼠标移进对像的时候
        show.onmouseover = function(){
            // console.log(1);
            clearInterval(Ti);
            clearInterval(Ti2);
        }
        // 鼠标移出对象的 时候
        show.onmouseout = function(){
            // console.log(2)
             clearInterval(Ti);
            clearInterval(Ti2);
             Ti2 = setTimeout(function(){
                Ti = setInterval('move(_bl)',5);
            }, 10);
        }

	</script>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值