首页 > 其他 > 详细

div轮流滚动显示

时间:2019-04-12 12:37:53      阅读:103      评论:0      收藏:0      [点我收藏+]
window.onload = function(){
    var _box1 = document.getElementById("box1");
    var _box2 = document.getElementById("box2");
    var y = 0;
    var fun = function(){
           _box1.style.top = y + ‘px‘;
           _box2.style.top = (y + 420) + ‘px‘;
           y--;
           if((y + 420) == 0){
            y = 0;
           }
      }
      setInterval(fun,20);
}

html部分

                      <div class="scroll_box" id="scroll_box">
                                        <div id="box1">
                                            <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </p>
                                        </div>
                                        <div id="box2">
                           <p>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx </p>
                        </div> 

                      </div>

 

css部分

#scroll_box {
    margin: 16px;
    position: relative;
    width: 468px;
    height: auto;
}
#scroll_box #box1, #scroll_box #box2 {
    position: absolute;
    height: 420px;
}
#scroll_box #box1 {
    top: 0;
}
#scroll_box #box2 {
    top: 420px;
}

 

div轮流滚动显示

原文:https://www.cnblogs.com/duanzhenzhen/p/10695182.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!