走马灯效果其实就是利用标签进行图片和文字滚动,设置的样式不一样,滚动的效果就不一样,实现“走马观花”的效果。
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </body> <marquee>这里是您要填的内容</marquee> </html>
<marquee behavior="slide">这里是您要填的内容</marquee>
这里是您要填的内容
图片滚动到右边界,自动再从左边滚动。
<marquee behavior="scroll"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
<marquee behavior="alternate"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
向左滚动
<marquee direction="left"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
向右滚动
<marquee direction="right"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
向下滚动
<marquee direction="down"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
向上滚动
<marquee direction="up"><img class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="img/border.png"></marquee>
<marquee loop="2">这里是您要填的内容</marquee>
<marquee bgcolor="#??????">这里是您要填的内容</marquee>
为了方便辨别,这里加上bgcolor属性。
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <body> <div > <p>初始化</p> <marquee bgcolor="red"; >这里是您要填的内容</marquee> </div> <div> <p>设置高度</p> <marquee bgcolor="aqua";width="380">这里是您要填的内容</marquee> </div> </body> </html>
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <body> <div > <p>初始化</p> <marquee bgcolor="red"; >这里是您要填的内容</marquee> </div> <div> <p>设置高度</p> <marquee bgcolor="aqua"; height="38">这里是您要填的内容</marquee> </div> </body> </html>
<marquee scrollamount="30">这里是您要填的内容</marquee>
本文以html为基础,主要介绍了常见的效果(跑马灯)的滚动原理,详细介绍了三种常见的滚动以及其相关属性,以及对设置参数时遇到的难题一一解答,希望能够帮助你学习。