本文主要為大家分享一篇10行原生JS實現文字無縫滾動的效果,特別簡單,具有很好的參考價值,希望對大家有所幫助,希望能幫助到大家。
廢話不多說,直接上程式碼
<section class="pro_quota_tip"> <p class="tip_box"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >aaaaaaaaa</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >bbbbbbbbbbbbbb</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >ccccccccccc</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >ddddddddddddddd</a> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >aaaaaaaaaaaaaa</a> </p> </section>
body,#app{ margin: 0; padding: 0; font-family:Helvetica; background: #f0efef !important; width: 100%; overflow-x: hidden; } a{ text-decoration: none; } .pro_quota_tip{ background: #fff; font-size: 14px; overflow: hidden; width: 200px; height: 49px; margin:0 auto; margin-top:10% } .pro_quota_tip .tip_box{ position: relative; } .pro_quota_tip .tip_box a{ color: red; display: block; width: 100%; padding:15px 5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
var tip_box_a_h = document.querySelectorAll('.tip_box a')[0].offsetHeight; var i=0; setInterval(()=>{ let startScroll = setInterval(()=>{ i++; document.querySelector('.tip_box').style.bottom = (tip_box_a_h/10)*i+'px'; if(i%10==0)clearInterval(startScroll); },50) if(i>(10*(document.querySelectorAll('.tip_box a').length-2)))i = 0; },2500)
絕對的10行,簡單實用,無依賴
相關推薦:
##實例詳解jQuery實現手風琴選單、層級選單、置頂選單、無縫捲動效果
以上是10行JS實現文字無縫滾動簡單方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!