html代碼: css代碼: #demo div{ color: #3a3a3a; font-size: .34rem; line-height: .8rem; } #demo div span{ color: #f65c53; } js代碼: <script> var speed = 40 var ...
html代碼:
<div style="position:relative; height:5rem"> <div id="demo" style="position:absolute;width:100%;height: 4rem; overflow:hidden; text-align:center;margin: .5rem 0;"> <div id="demo1"> <p><span>廣東省廣州市 網友:186****0751</span>通過提交需求得到了律師幫助</p> <p><span>江蘇省南京市 網友:138****7913</span>通過提交需求得到了律師幫助</p> <p><span>廣西省南寧市 網友:136****8755</span>通過提交需求得到了律師幫助</p> <p><span>浙江省杭州市 網友:188****3421</span>通過提交需求得到了律師幫助</p> <p><span>廣東省惠州市 網友:134****2244</span>通過提交需求得到了律師幫助</p> <p><span>廣東省東莞市 網友:132****9649</span>通過提交需求得到了律師幫助</p> <p><span>湖南省長沙市 網友:138****1354</span>通過提交需求得到了律師幫助</p> <p><span>湖北省武漢市 網友:189****8828</span>通過提交需求得到了律師幫助</p> </div> <div id="demo2"></div> </div> </div>
css代碼:
#demo div{ color: #3a3a3a; font-size: .34rem; line-height: .8rem; } #demo div span{ color: #f65c53; }
js代碼:
<script> var speed = 40 var demo = document.getElementById("demo"); var demo2 = document.getElementById("demo2"); var demo1 = document.getElementById("demo1"); demo2.innerHTML = demo1.innerHTML; function Marquee() { if (demo2.offsetTop - demo.scrollTop <= 0) { demo.scrollTop -= demo1.offsetHeight; } else { demo.scrollTop++; } } var MyMar = setInterval(Marquee, speed); demo.onmouseover = function () { clearInterval(MyMar) } demo.onmouseout = function () { MyMar = setInterval(Marquee, speed) } </script>註意:內容的高度必須大於容器的高度,否則無法滾動