10行原生JS实现文字无缝滚动(超简单)
2019/6/27 20:29:17
本文主要是介绍10行原生JS实现文字无缝滚动(超简单),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
废话不多说,直接上代码
<section class="pro_quota_tip"> <div 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> </div> </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行,简单实用,无依赖
以上这篇10行原生JS实现文字无缝滚动(超简单)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于10行原生JS实现文字无缝滚动(超简单)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-24Vue CLI多环境配置学习:从入门到实践
- 2024-11-24Vue CLI多环境配置学习:新手入门教程
- 2024-11-24Vue CLI学习:初学者指南
- 2024-11-24Vue CLI学习:从入门到上手的简单教程
- 2024-11-24Vue3+Vite学习:从零开始的前端开发之旅
- 2024-11-24Vue3阿里系UI组件学习入门教程
- 2024-11-24Vue3的阿里系UI组件学习入门指南
- 2024-11-24Vue3公共组件学习:新手入门教程
- 2024-11-24Vue3公共组件学习入门指南
- 2024-11-24vue3核心功能响应式变量学习