本篇文章给大家带来的内容是关于实现marquee滚动(代码示例),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
背景:marquee标签在有些浏览器兼容性不好,就手动用原生js实现了下。
横着滚动效果链接描述
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1.0, maximum-scale=1, user-scalable=no" /> <meta content="telephone=no" name="format-detection" /> <title>传奇无双1215</title> <meta name="keywords" content="传奇无双1215"> <meta name="description" content="传奇无双1215"> <script> (function (_D) { var _self = {}; _self.resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'; _self.Html = _D.getElementsByTagName("html")[0]; _self.widthProportion = function () { var p = Number((_D.body && _D.body.clientWidth || _self.Html.offsetWidth) / 720).toFixed(3); return p > 1.067 ? 1.067 : p < 0.444 ? 0.444 : p; }; _self.changePage = function () { _self.Html.setAttribute("style", "font-size:" + _self.widthProportion() * 100 + "px"); }; _self.changePage(); if (!document.addEventListener) return; window.addEventListener(_self.resizeEvt, _self.changePage, false); document.addEventListener('DOMContentLoaded', _self.changePage, false); })(document); </script> <style> body { overflow-x: hidden; font: .36rem/1.5 Arial, "Microsoft YaHei", SimSun; margin: 0; padding: 0; font-size: .22rem } body, p { margin: 0; padding: 0; } em { font-style: normal; font-weight: 400 } img { font-size: 0; line-height: 0; border: 0; display: block; width: 100%; } .box { margin: 0 auto; max-width: 720px; width: 100%; background: #260b0c; } .pr { position: relative } .marquee { overflow: hidden; position: absolute; bottom: 11.5%; left: 0; width: 84%; margin: 0 8%; height: .4rem } #m em { float: right; color: #fff } #m { position: absolute; height: 0.4rem; display: block; line-height: .35rem } #m p { float: left; line-height: .4rem; margin-right: 40px; color: #d4be8d } #m span { margin-right: 30px; } </style> </head> <body> <div class="box"> <div class="pr"> <img class="img" src="images/02.jpg" /> <div class="marquee"> <div id="m"> <p> <em>888新快币</em> <span>xk12*****8抽中</span></p> <p> <em>88dfdfdfd8新快币</em> <span>xk1dfdfd2*****8抽中</span></p> <p> <em>888新快币</em> <span>xk12*****8抽中</span></p> <p> <em>888新快币</em> <span>xk12*****8抽中</span></p> <p> <em>888新快币</em> <span>xk12*****8抽中</span></p> <p> <em>888新快币</em> <span>xk12*****8抽中</span></p> </div> </div> </div> </div> <script> var timer; var m = document.getElementById("m") var init_left = document.querySelector(".box").clientWidth * 0.8; var m_left = init_left; var m_width = 0; function setTimer() { timer = setInterval(function () { m_left -= 1; if (m_left <= -m_width + 20) { m_left = init_left; } m.style.left = m_left + 'px' }, 10) } function marquee() { var p = m.querySelectorAll("p"); for (var i = 0, l = p.length; i < l; i++) { m_width += p[i].clientWidth + 48 } console.log(m_width) m.style.width = m_width + 'px' m.style.left = init_left + 'px' setTimer(); m.addEventListener("mouseover", function () { clearInterval(timer); }) m.addEventListener("mouseout", function () { setTimer(); }) } marquee() </script> </body> </html>
竖着滚动效果链接描述
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1.0, maximum-scale=1, user-scalable=no" /> <meta content="telephone=no" name="format-detection" /> <title>万圣节1101</title> <meta name="keywords" content="万圣节1101"> <meta name="description" content="万圣节1101"> <script> (function (_D) { var _self = {}; _self.resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize'; _self.Html = _D.getElementsByTagName("html")[0]; _self.widthProportion = function () { var p = Number((_D.body && _D.body.clientWidth || _self.Html.offsetWidth) / 720).toFixed(3); return p > 1.067 ? 1.067 : p < 0.444 ? 0.444 : p; }; _self.changePage = function () { _self.Html.setAttribute("style", "font-size:" + _self.widthProportion() * 100 + "px"); }; _self.changePage(); if (!document.addEventListener) return; window.addEventListener(_self.resizeEvt, _self.changePage, false); document.addEventListener('DOMContentLoaded', _self.changePage, false); })(document); </script> <style> body { margin: 0; padding: 0 } em { font-style: normal; font-weight: 400 } .pr { position: relative } img { font-size: 0; line-height: 0; border: 0; width: 100%; } .box { width: 100%; max-width: 720px; background: #260b0c } .marquee { overflow: hidden; position: absolute; bottom: 17%; left: 0; width: 54%; margin: 0 23%; height: 1.5rem } #m, #m p { font-size: .22rem } #m em { float: right } #m { position: absolute; top: 1.6rem; width: 100% } #m p { color: #c1d1ff } #m em { color: #ffab2a } </style> </head> <body> <div class="box"> <div class="pr"> <img src="images/04.jpg" /> <div class="marquee"> <div id="m"> <p> <em>888新快币</em>xk12*****8抽中</p> <p> <em>488新快币</em>xk12*****8抽中</p> <p> <em>188新快币</em>xk12*****8抽中</p> <p> <em>88新快币</em>xk12*****8抽中</p> </div> </div> </div> </div> <script> //marquee var timer, m_height; var m = document.getElementById("m") m_height = m.clientHeight; var marquee_height = document.querySelector(".marquee").clientHeight; var m_top = marquee_height; function setTimer() { timer = setInterval(function () { m_top -= 1; if (m_top <= -m_height) { m_top = marquee_height; } m.style.top = m_top + 'px'; }, 10) } function marquee() { setTimer(); m.addEventListener("mouseover", function () { clearInterval(timer); }) m.addEventListener("mouseout", function () { setTimer(); }) } marquee() </script> </body> </html>
以上是实现marquee滚动(代码示例)的详细内容。更多信息请关注PHP中文网其他相关文章!

H5代码的最佳实践包括:1.使用正确的DOCTYPE声明和字符编码;2.采用语义化标签;3.减少HTTP请求;4.使用异步加载;5.优化图像。这些实践能提升网页的效率、可维护性和用户体验。

Web标准和技术从HTML4、CSS2和简单的JavaScript演变至今,经历了显着的发展。 1)HTML5引入了Canvas、WebStorage等API,增强了Web应用的复杂性和互动性。 2)CSS3增加了动画和过渡功能,使页面效果更加丰富。 3)JavaScript通过Node.js和ES6的现代化语法,如箭头函数和类,提升了开发效率和代码可读性,这些变化推动了Web应用的性能优化和最佳实践的发展。

H5不仅仅是HTML5的简称,它代表了一个更广泛的现代网页开发技术生态:1.H5包括HTML5、CSS3、JavaScript及相关API和技术;2.它提供更丰富、互动、流畅的用户体验,能在多设备上无缝运行;3.使用H5技术栈可以创建响应式网页和复杂交互功能。

H5与HTML5指的是同一个东西,即HTML5。HTML5是HTML的第五个版本,带来了语义化标签、多媒体支持、画布与图形、离线存储与本地存储等新功能,提升了网页的表现力和交互性。

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

H5开发需要掌握的工具和框架包括Vue.js、React和Webpack。1.Vue.js适用于构建用户界面,支持组件化开发。2.React通过虚拟DOM优化页面渲染,适合复杂应用。3.Webpack用于模块打包,优化资源加载。

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5通过语义化元素和ARIA属性提升网页的可访问性和SEO效果。1.使用、、等元素组织内容结构,提高SEO。2.ARIA属性如aria-label增强可访问性,辅助技术用户可顺利使用网页。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

SublimeText3汉化版
中文版,非常好用

Atom编辑器mac版下载
最流行的的开源编辑器