广告条滑入滑出源代码实现

广告条滑入滑出源代码实现

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>广告条滚动</title>
<style type="text/css">
    *{
        padding: 0px;
        margin: 0 auto;
    }
    #ad{
        width:1000px;
        height:300px;
        font-size: 50px;
        background: red;
        font-weight: 1000;
        font-size: 100px;
        /*margin-top:-300px;*/
    }
    #box{
        width:1000px;
        height:800px;
        background: green;

    }
</style>

<script type="text/javascript">
window.οnlοad=function(){
    var oad=document.getElementById('ad');//获得ad元素
    
    var timer=setInterval(function(){//定时器向下滑
        var oldtop=parseInt(oad.style.marginTop);//获得ad离上边的距离
        oldtop+=10;//距离增大
        oad.style.marginTop=oldtop+'px';//赋值
        
        if(oldtop==0){//如果到达位置,关闭定时器
            clearInterval(timer);
        }
    },30);

    setTimeout(function(){//3秒后执行
        var time=setInterval(function(){//30毫秒执行一次
            var oldtop=parseInt(oad.style.marginTop);//获得ad离上边的距离
            oldtop-=10;//距离减小
            oad.style.marginTop=oldtop+'px';//赋值
            
            if(oldtop==-300){//到达位置,关闭定时器
                clearInterval(time);
            }
        },30)
    },3000)
}
</script>

</head>
<body>
    <div id="ad" style="margin-top:-300px;">欢迎来到本网站</div>
    <div id="box"></div>
</body>
</html>

 

转载于:https://www.cnblogs.com/lzzhuany/p/4589915.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值