公告栏自动滚动例子代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>

    <style>



* {
            margin: 0px;
            padding: 0px;            /*  去掉所有标签的marign和padding的值  */
        }
        ul {
            list-style: none;           /*  去掉ul标签默认的点样式  */
        }
        a {
            color: #333;
            font-size: 12px;
            text-decoration: none;     /* 超链接样式 */
        }
        a:hover {
            color: #ff0000;
        }
        #main {
            width: 399px;
            border: 5px solid #ababab;
            -moz-border-radius: 15px;      /* Gecko browsers */
            -webkit-border-radius: 15px;   /* Webkit browsers */
            border-radius: 15px;
            box-shadow: 2px 2px 10px #ababab;
            margin: 50px auto 0;
            text-align: left;               /* 让新闻内容靠左 */
        }
        /*  头部样式 */
        #title {
            height: 62px;
            overflow: hidden;  /* 内容超出的部分要隐藏,免得撑高头部 */
            font-size: 26px;
            line-height: 62px;
            padding-left: 30px;
            background-image: -moz-linear-gradient(top, #f05e6f, #c9394a); /* Firefox */
            background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #f05e6f), color-stop(1, #c9394a)); /* Saf4+, Chrome */
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#8fa1ff', endColorstr='#f05e6f', GradientType='0'); /* IE*/
            border: 1px solid #f05e6f;
            -moz-border-radius: 8px 8px 0 0;      /* Gecko browsers */
            -webkit-border-radius: 8px 8px 0 0;   /* Webkit browsers */
            border-radius: 8px 8px 0 0;
            color: #fff;
            position: relative;
        }
        #title a {
            position: absolute;
            right: 10px;
            bottom: 10px;
            display: inline;
            color: #fff;
            font-size: 12px;
            line-height: 24px;
        }
        #box {
            height: 144px;
            width: 335px;
            margin-left: 25px;
            margin-top: 10px;
            overflow: hidden;    /* 超出的内容部分要隐藏,免得撑高中间部分 */
        }
        #main ul li {
            height: 24px;
        }
        #main ul li a {
            float: left;
            text-indent: 15px;
        }
        #main ul li span {
            float: right;
            color: #999;
        }
    </style>
</head>
<body>
    
<div  id="main">
    <h3 id="title">Title</h3>
    <div  id="box">
        <ul id="con1">
            <li><a href="#">1.学会html5 绝对的屌丝逆袭</a><span>2016-06-01</span></li>
            <li><a href="#">2.tab页面切换效果(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">3.圆角水晶按钮制作(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">4.HTML+CSS基础课程(系列)</a><span>2016-06-01</span></li>
            <li><a href="#">5.分页页码制作(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">6.导航条菜单的制作(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">7.信息列表制作(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">8.下拉菜单制作(案例)</a><span>2016-06-01</span></li>
            <li><a href="#">9.如何实现“新手引导”效果</a><span>2016-06-01</span></li>
        </ul>
        <ul id="con2">    /*  滚动需要  */
     </ul> 
 </div> 
</div>


<script>
    
var area = document.getElementById('box');
    var con1 = document.getElementById('con1');
    var con2 = document.getElementById('con2');
    var speed = 50;
    area.scrollTop = 0;
    con2.innerHTML = con1.innerHTML;
    function scrollUp(){
        if(area.scrollTop >= con1.scrollHeight) {
            area.scrollTop = 0;
        }else{
            area.scrollTop ++;
        }
    }
    var myScroll = setInterval("scrollUp()",speed);
    area.onmouseover = function(){
        clearInterval(myScroll);
    }
    area.onmouseout = function(){
        myScroll = setInterval("scrollUp()",speed);
    }

</script>

</body>
</html>

 

posted @ 2019-02-19 10:23  MagicAsa  阅读(1462)  评论(0编辑  收藏  举报