上下滚动轮播条

源码 :
hao_roll = {
    id:null,
    speed:30,
    timer:null,
    Num:0,
    oLiH:0,
    aLiH:0,
    mouseOn:false,
    json:null,
    //    初始化
    init:function(obj){
        this.json = {};
        for(var i in obj) {
            this.json[i] = obj[i];
        }
        this.oNav = document.getElementById(this.json.id);
//        alert(this.oNav.parentNode);
        var aLi = this.oNav.getElementsByTagName('li');
        //设置样式
        this.oNav.parentNode.style.position="relative";
        this.oNav.style.position='absolute';
        this.oNav.style.left='0';
        this.oNav.style.top='0';
        for(var i=0; i<aLi.length; i++){
            aLi[i].style.float = 'left';
        }
        this.oLiH = aLi[0].offsetHeight;
        this.aLiH = this.oLiH*aLi.length*2;
        this.oNav.innerHTML+=this.oNav.innerHTML;
//        console.log(this.aLiH)
    },
    //    定时器
    Timer:function(){
        this.timer = setInterval(function(){
            hao_roll.Num--;
//            console.log(hao_roll.Num);
            if(hao_roll.Num<=(-hao_roll.aLiH/2)){
                hao_roll.Num=1;
            }
            hao_roll.oNav.style.top = hao_roll.Num+'px'
        },this.speed);
    },
    //    事件执行
    roll:function(obj){
//        console.log(obj);
        hao_roll.init(obj);
        this.id = this.json.id;
        this.speed = this.json.speed;
        this.mouseOn = this.json.mouseOn;
        this.Timer();
        if(this.mouseOn){
            hao_roll.oNav.onmouseover = function(){
                hao_roll.moseover();
            };
            hao_roll.oNav.onmouseout = function(){
                hao_roll.moseout();
            };
        }
    },
    //鼠标移上清除定时器
    moseover:function(){
            clearInterval(this.timer);
    },
    //鼠标移开定时器继续运行
    moseout:function(){
        this.Timer()
    }
};
html代码:
</pre><pre name="code" class="html"><!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{margin: 0; padding: 0;}
        .tab{width: 900px; height: 30px; overflow: hidden;  margin: 100px auto;}
        .nav{width: 900px; overflow: hidden; }
        .nav ul{width:900px; overflow: hidden;}
        .nav ul li{width: 900px; height: 30px; background: #000000;text-align: center; color: #FFFFFF; list-style: none ; line-height: 30px; cursor: pointer}
        .nav .a{background: #ff0000;}
        .nav .b{background: #000000;}
        .nav .c{background: #0038c0;}




    </style>
</head>
<body>
<div class="tab">
    <div class="nav" id="Nav">
        <ul>
            <li class="a">第一行</li>
            <li class="b">第二行</li>
            <li class="c">第三行</li>
        </ul>
    </div>
</div>
<script src="js/hao_roll.js"></script>
<script>
    hao_roll.roll({
        id:'Nav', //设置ID
        speed:30, //设置滚动速度单位毫秒
        mouseOn:true  //是否打开鼠标移上停止滚动默认是false
    });
</script>
</body>
</html>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值