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;
}

 

相关文章:

  • 2022-01-09
  • 2021-12-26
  • 2021-10-18
  • 2021-09-01
  • 2021-12-05
  • 2021-12-08
猜你喜欢
  • 2022-01-09
  • 2021-10-25
  • 2021-10-13
  • 2022-01-24
  • 2022-03-03
  • 2022-02-01
  • 2021-06-28
相关资源
相似解决方案