div实现向左右无缝滚动图片效果(跑马灯)
转载:图片左向无缝滚动的实现
function TxtMarquee(marqueeBox, delaytime, direction, itemCell){
if(delaytime == undefined)delaytime = 50;
if(direction == undefined)direction = "up";
}
}
switch(direction){
case "left":
var oScroll=setInterval(ScrollLeft, delaytime);
oMarquee.hover(function(){
clearInterval(oScroll);
}, function(){
}
.picList .pe_u_thumb A:hover IMG {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; BORDER-BOTTOM: #999 1px solid
三、几点说明:
1、调用图片的标签{bel id="通用带图片的信息列表"/}参数,可以根据自己需要进行修改。
2、“ZENroll”是滚动模块id名,需要在JS代码、风格中保持同一名称。
3、只提供左向滚动,自己只能修改滚动延迟时间,也就是滚动速度,第二个参数数字起小,滚动越快。
4、前台图片的大小等效果可以通过修改风格来达到,比如缩约图大小可以修改“.picScroll .picList LI IMG ”来完成。
}
.picScroll .picList LI IMG {
跑马灯效果详解
一、一般跑马灯<div id="c_9"><marquee direction="left" TrueSpeed scrollamount="1" scrolldelay="30" onMouseOver="this.stop();" onMouseOut="this.start();"><img src="images/p_0/p_1.jpg" width="150" height="130" border="1" /><img src="images/p_0/p_2.jpg" width="150" height="130" border="1" /><img src="images/p_0/p_3.jpg" width="150" height="130" border="1" /> </marquee></div>附:循环滚动基本语法<marquee> ... </marquee>移动属性的设置 ,这种移动不仅仅局限于文字,也可以应用于图片,表格等等方向<direction=#> #=left, right ,up ,down <marquee direction=left>从右向左移!</marquee>方式<bihavior=#> #=scroll, slide, alternate <marquee behavior=scroll>一圈一圈绕着走!</marquee><marquee behavior=slide>只走一次就歇了!</marquee><marquee behavior=alternate>来回走</marquee>循环<loop=#> #=次数;若未指定则循环不止(infinite) <marquee loop=3 width=50% behavior=scroll>只走 3 趟</marquee> <P><marquee loop=3 width=50% behavior=slide>只走 3 趟</marquee><marquee loop=3 width=50% behavior=alternate>只走 3 趟!</marquee>速度<scrollamount=#> <marquee scrollamount=20>啦啦啦,我走得好快哟!</marquee>延时<scrolldelay=#> <marquee scrolldelay=500 scrollamount=100>啦啦啦,我走一步,停一停!</marquee>外观(Layout)设置对齐方式(Align)<align=#> #=top, middle, bottom <font size=6><marquee align=# width=400>啦啦啦,我会移动耶!</marquee></font>底色<bgcolor=#> #=rrggbb 16 进制数码,或者是下列预定义色彩:Black, Olive, Teal, Red, Blue, Maroon, Navy, Gray, Lime,Fuchsia, White, Green, Purple, Silver, Yellow, Aqua <marquee bgcolor=aaaaee>颜色!</marquee>面积<height=# width=#> <marquee height=40 width=50% bgcolor=aaeeaa>面积!</marquee>空白(Margins)<hspace=# vspace=#><marquee hspace=20 vspace=20 width=150 bgcolor=ffaaaa align=middle>面积!</marquee>二、无间断循环跑马灯效果<HTML><HEAD><TITLE>向左不间断(无缝)滚动图片js代码 - 中国asp之家收集整理 -</TITLE><META http-equiv=Content-Type content="text/html; charset=gb2312"><link href="css/index.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE style="BORDER: #DEE0E0 1px solid;" cellSpacing=0 cellPadding=0width=500 align=center border=0><TBODY><TR><TD width="100%" height="125" align="center"><DIV id=demo style="OVERFLOW: hidden; WIDTH: 99%;"><TABLE cellSpacing=0 cellPadding=0 align=left border=0 cellspace="0"> <TBODY><TR><TD id=demo1 vAlign=top><table height="116" border="0"cellpadding="0" cellspacing="0"><tr><td><table width="135" height="125" border="1" align="center" cellpadding="0" cellspacing="3" bordercolor="#CC3300"><tr><%sql="select * from tbl_photos order by p_id desc"rst.open sql,conn,1,1do while not rst.eof%><td width="100" align="center" valign="middle"><% if rst("p_image")<>"" then %><a href="photosshow_1.asp?id=<%=rst("p_id")%>" target="_blank"><img src="photos/<%=rst("p_image")%>" alt="<%=rst("p_title")%>" width="125" height="115" border="0" align="middle" onMouseOver="this.width=124;this.height=114" onMouseOut="this.width=125;this.height=115"></a><% else %><a href="<%=rst("p_title")%>"><%=rst("p_content")%></a> <% end if%></td><%rst.movenextlooprst.close%></tr></table></td></tr></table></TD><TD id=demo2 vAlign=top> </TD></TR></TBODY></TABLE></DIV><SCRIPT>var speed3=25//速度数值越大速度越慢demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetWidth-demo.scrollLeft<=0)demo.scrollLeft-=demo1.offsetWidthelse{demo.scrollLeft++}}var MyMar=setInterval(Marquee,speed3)demo.onmouseover=function() {clearInterval(MyMar)}demo.onmouseout=function() {MyMar=setInterval(Marquee,speed3)} </SCRIPT></TD></TR></TBODY></TABLE></BODY></HTML>。
向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)
shenxiufang 415238773<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>向上下左右不间断无缝滚动图片的效果(兼容火狐和IE)</title></head><body>下面是向上滚动代码<!--下面是向上滚动代码--><div id="colee" style="overflow:hidden;height:253px;width:410px;"><div id="colee1"><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p></div><div id="colee2"></div></div><script>var speed=30;var colee2=document.getElementById("colee2");var colee1=document.getElementById("colee1");var colee=document.getElementById("colee");colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2function Marquee1(){//当滚动至colee1与colee2交界时if(colee2.offsetTop-colee.scrollTop<=0){colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端}else{colee.scrollTop++}}var MyMar1=setInterval(Marquee1,speed)//设置定时器//鼠标移上时清除定时器达到滚动停止的目的colee.onmouseover=function() {clearInterval(MyMar1)}//鼠标移开时重设定时器colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}</script><!--向上滚动代码结束--><br>下面是向下滚动代码<!--下面是向下滚动代码--><div id="colee_bottom" style="overflow:hidden;height:253px;width:410px;"> <div id="colee_bottom1"><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p><p><img src="1.jpg"></p></div><div id="colee_bottom2"></div></div><script>var speed=30var colee_bottom2=document.getElementById("colee_bottom2");var colee_bottom1=document.getElementById("colee_bottom1");var colee_bottom=document.getElementById("colee_bottom");colee_bottom2.innerHTML=colee_bottom1.innerHTMLcolee_bottom.scrollTop=colee_bottom.scrollHeightfunction Marquee2(){if(colee_bottom1.offsetTop-colee_bottom.scrollTop>=0)colee_bottom.scrollTop+=colee_bottom2.offsetHeightelse{colee_bottom.scrollTop--}}var MyMar2=setInterval(Marquee2,speed)colee_bottom.onmouseover=function() {clearInterval(MyMar2)}colee_bottom.onmouseout=function() {MyMar2=setInterval(Marquee2,speed)} </script><!--向下滚动代码结束--><br>下面是向左滚动代码<!--下面是向左滚动代码--><div id="colee_left" style="overflow:hidden;width:500px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td id="colee_left1" valign="top" align="center"><table cellpadding="2" cellspacing="0" border="0"><tr align="center"><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td></tr></table></td><td id="colee_left2" valign="top"></td></tr></table></div><script>//使用div时,请保证colee_left2与colee_left1是在同一行上.var speed=30//速度数值越大速度越慢var colee_left2=document.getElementById("colee_left2");var colee_left1=document.getElementById("colee_left1");var colee_left=document.getElementById("colee_left");colee_left2.innerHTML=colee_left1.innerHTMLfunction Marquee3(){if(colee_left2.offsetWidth-colee_left.scrollLeft<=0)//offsetWidth 是对象的可见宽度colee_left.scrollLeft-=colee_left1.offsetWidth//scrollWidth 是对象的实际内容的宽,不包边线宽度else{colee_left.scrollLeft++}}var MyMar3=setInterval(Marquee3,speed)colee_left.onmouseover=function() {clearInterval(MyMar3)}colee_left.onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}</script><!--向左滚动代码结束--><br>下面是向右滚动代码<!--下面是向右滚动代码--><div id="colee_right" style="overflow:hidden;width:500px;"><table cellpadding="0" cellspacing="0" border="0"><tr><td id="colee_right1" valign="top" align="center"><table cellpadding="2" cellspacing="0" border="0"><tr align="center"><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td><td><img src="1.jpg"></td></tr></table></td><td id="colee_right2" valign="top"></td></tr></table></div><script>var speed=30//速度数值越大速度越慢var colee_right2=document.getElementById("colee_right2");var colee_right1=document.getElementById("colee_right1");var colee_right=document.getElementById("colee_right");colee_right2.innerHTML=colee_right1.innerHTMLfunction Marquee4(){if(colee_right.scrollLeft<=0)colee_right.scrollLeft+=colee_right2.offsetWidthelse{colee_right.scrollLeft--}}var MyMar4=setInterval(Marquee4,speed)colee_right.onmouseover=function() {clearInterval(MyMar4)}colee_right.onmouseout=function() {MyMar4=setInterval(Marquee4,speed)} </script><!--向右滚动代码结束--></body></html>。
详解如何用div实现自制滚动条
详解如何⽤div实现⾃制滚动条滚动条是浏览器中最常见的组件了。
然⽽,滚动条的颜值总是不能令⼈满意,特别是嵌⼊在页⾯中的滚动条:漂亮的⽹页突然出现⼀根灰灰的滚动条真是太煞风景了。
虽然浏览器也提供了⼀些伪类能改善滚动条的外观,但改善程度也是有限。
为什么不⾃⼰⽤ div 实现⼀根萌萌的滚动条呢,⽐如这根:贪吃蛇滚动条今天就来讲讲如何⽤ div ⾃⼰实现滚动条。
1. 先得有滚动条在开始之前,我们要先隐藏浏览器本⾝的滚动条,加上⾃制的滚动条<body><div id="container"><div class="scrollbar"></div>bla bla bla ... ⼀⼤段⼀屏显⽰不下的内容</div></body>我们在需要滚动条的 div 中增加了⼀个 class="scroll" 的 div 代表滚动条,给这个 div 来点样式:html, body, #container {height: 100%;margin: 0;}#container {padding: 2rem;box-sizing: border-box; // 为了设置padding时不增加元素本⾝⾼度,避免出现滚动条overflow-y: hidden; // 隐藏浏览器本⾝的滚动条position: relative;padding-right: 30px; // 给⾃制滚动条留点空间,不要其他内容重合了}.scrollbar {height: 166px;width: 20px;border-radius: 20px;background: #ccc;position: absolute; // 绝对定位,⽅便设置滚动条位置right: 0; // 设置滚动条在最右边}⼀个简易的滚动条就有了:虽然⽐浏览器默认的滚动条好不到哪⼉去,不过你可以⾃由发挥,把GIF动图作为滚动条也是可以的。
简单的跑马灯效果(轮播图)
简单的跑马灯效果(轮播图)逻辑简介:想要图⽚或者是⽂字向左移动,那肯定得⽤到定时器,那么移动那就必然是距离左边的left值在改变;核⼼问题就是通过定时器来改变ul距离left的值;本姑娘就是简简单单直直接接,上代码吧。
如有什么不懂可以提问。
效果图:到⽅法⼀:可以⽤⼀个标签搞定,即是:<marquee>ddddddd</marquee>⽅法⼆:还是⽼⽼实实的⽤js写1 <!DOCTYPE html>2 <html lang="en">3 <head>4 <meta charset="UTF-8">5 <title>跑马灯</title>6 <style>7 .outBox{width:400px;height:40px;overflow: hidden;margin:0 auto;border:1px solid #419BF9;position:relative;background-color: #2B2F33;color:#ffffff;border-radius:4px;}8 .ulPmd{width:600px;height:40px;position:absolute;left:0;top:0}9 .ulPmd li{width:auto;height:40px;float:left;list-style: none;margin-left:20px;line-height:8px}10 </style>11 <script src="js/jquery-3.1.0.min.js"></script>12 <script>13 $(function () {14var i=0;15var timer;16 timer=setInterval(function(){17//根据ul的位移来判断⼀秒钟向左移动的距离;18if(i>$('li').length){19 i=1;20 }else{21 i++;22 }23var ulLeft=-($('li').width())*i;24 $('.ulPmd').css('left',ulLeft)25 },1000);26//⿏标滑过li的时候,清除定时器27 $('li').on('mouseover',function () {28 clearInterval(timer)29 });30//⿏标滑出li的时候,继续定时器31 $('li').on('mouseout',function () {32 timer=setInterval(function() {33//根据ul的位移来判断⼀秒钟向左移动的距离;34if(i>$('li').length){35 i=1;36 }else{37 i++;38 }39var ulLeft=-($('li').width())*i;40 $('.ulPmd').css('left',ulLeft)41 },1000);42 })43 })4445 </script>46 </head>47 <body>48 <div class="outBox">49 <ul class="ulPmd">50 <li>item1</li>51 <li>item2</li>52 <li>item3</li>53 <li>item4</li>54 <li>item6</li>55 <li>item7</li>56 <li>item8</li>57 <li>item9</li>58 <li>item10</li>59 </ul>60 </div>6162 </body>63 </html>。
图片左右循环连续滚动代码,解决marquee的留白问题
图片左右循环连续滚动代码,解决marquee的留白问题向上:<div id=demo style="overflow:hidden; width:128px; heig ht:300px;"><div id=demo1><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br></div><div id=demo2></div></div><script language="javascript">var speed=30demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetTop-demo.scrollT op<=0)demo.scrollTop-=demo1.offsetHeightelse{demo.scrollTop++}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function(){clearInterval(MyMar)}demo.onmouseout=function(){MyMar=setInterval(Marquee ,speed)}</script>====================================== ========================================= ============向下:<div id=demo style="overflow:hidden; width:128px; heig ht:300px;"><div id=demo1><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br><img src="1.gif"><br><img src="2.gif"><br><img src="3.gif"><br></div><div id=demo2></div></div><script language="javascript">var speed=30demo2.innerHTML=demo1.innerHTMLdemo.scrollTop=demo.scrollHeightfunction Marquee(){if(demo1.offsetTop-demo.scrollT op>=0)demo.scrollTop+=demo2.offsetHeightelse{demo.scrollTop--}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function(){clearInterval(MyMar)}demo.onmouseout=function(){MyMar=setInterval(Marquee ,speed)}</script>====================================== ========================================= ============向左:<div id=demo style="overflow:hidden;height:100px;width: 800px;"><table align=left cellpadding=0 cellspace=0 border=0> <tr><td id=demo1 valign=top ><img src="1.gif"width="200"><img src="2.gif" width="200" ><img src="3.gif" width="200" ><img src="4.gif" width="200"><img src="5.gif" width="200" ><img src="6.gif " width="200" ></td><td id=demo2 valign=top ></td></tr></table></div><script>var speed=10demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetWidth-demo.scrollLeft<=0)demo.scrollLeft-=demo1.offsetWidthelse{demo.scrollLeft++}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function(){clearInterval(MyMar)}demo.onmouseout=function(){MyMar=setInterval(Marquee,speed)}</script>====================================== ============================================向右:<div id=demo style="overflow:hidden;height:100px;width: 300px;"><table align=left cellpadding=0 cellspace=0 border=0> <tr><td id=demo1 valign=top><img src="1.gif"><img src="2.gif"><img src="3.gif"><img src="4.gif"><img src="5.gif"> <img src="6.gif"></td><td id=demo2 valign=top></td></tr></table></div><script>var speed=30demo2.innerHTML=demo1.innerHTMLdemo.scrollLeft=demo.scrollWidthfunction Marquee(){if(demo.scrollLeft<=0)demo.scrollLeft+=demo2.offsetWidthelse{demo.scrollLeft--}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function() {clearInterval(MyMar)}demo.onmouseout=function() {MyMar=setInterval(Marque e,speed)}</script>====================================== ========================================= =============在实现左右循环滚动时,请注意设置最外层的width属性的值,一般为2:1的比例,试试看,如果设置不合适,可以看到图片,但不会滚动!!。
div实现向左右无缝滚动图片效果(跑马灯)
div实现向左右无缝滚动图片效果(跑马灯)div实现向左右无缝滚动图片效果(跑马灯)div+css学习笔记22(用div实现向左无缝滚动图片效果)JavaScript实现走马灯效果[无缝连接、循环滚动] 无缝跑马灯效果以下代码在IE6、Firefox+Win2k环境下测试通过网页走马灯连续循环滚动废话少说,代码贴出来:<div id="imgmarquee" style="OVERFLOW: hidden; WIDTH: 580px; align: left; background-color:#0099CC;"> <div style="width:1200px"><!--id="marquePic1"里面的宽度一定要大于id="imgmarquee"的宽度才能看到效果width:600px;>WIDTH: 580px;大的div宽度要为span的两倍才可以,不然会换行width:1200px zdz的作品,流风的作品--> <span id="marquePic1"style="width:600px; background-color:#990033;"><img src="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> </span><span id="marquePic2"style="width:600px;background-color:#990033;"></sp an> </div></div> <scripttype="text/javascript"> var imgmarquee = document.getElementById('imgmarquee');var marquePic2 = document.getElementById('marquePic2');var marquePic1 = document.getElementById('marquePic1');var speed=10;//控制移动的速度,数越大越慢marquePic2.innerHTML=marquePic1.innerHTML;//把marquePic1的内容复制到marquePic2里面function Marquee(){ if(imgmarquee.scrollLeft>=marquePic1.scro llWidth){ imgmarquee.scrollLeft=0;}else{ //demo.scrollLeft+ +; imgmarquee.scrollLeft++; }} varmarqueetemp=setInterval(Marquee,speed); imgmarquee.onmouseover=function(){clearInterval(marqueetemp)} //鼠标移到上面停止并清除计数imgmarquee.onmouseout=function(){marqueetemp=setInterval(Marquee,speed)} //鼠标离开重新计数</script>------------参考资料(向右,向上,向下代码同理,只是控制的js不同而已,把下面的id改成对应的就ok了)------------向右------------<scriptlanguage="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //数值越大滚动速度越慢demo2.innerHTML =demo1.innerHTML;demo.scrollLeft =demo.scrollWidth;functionMarquee(){ if(demo.scrollLeft<=0)demo.scrollLeft+=demo2.offsetWidthelse{ demo.scrollLeft-- }}var MyMar = setInterval(Marquee,speed)demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)}--></script>-------------向下-------------<scriptlanguage="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //数值越大滚动速度越慢demo2.innerHTML =demo1.innerHTML;demo.scrollTop =demo.scrollHeight;functionMarquee(){ if(demo1.offsetTop-demo.scrollTop>=0) demo.scrollTop+=demo2.offsetHeightelse{ demo.scrollTop-- }}var MyMar = setInterval(Marquee,speed);demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)}--></script>-----------向上-----------<script language="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //滚动速度值,值越大速度越慢demo2.innerHTML =demo1.innerHTML //克隆demo2为demo1function Marquee(){ if(demo2.offsetT op-demo.scrollT op<=0) //当滚动至demo1与demo2交界时demo.scrollTop-=demo1.offsetHeight //demo跳到最顶端else{ demo.scrollTop++ }}var MyMar = setInterval(Marquee,speed); //设置定时器demo.onmouseover = function(){clearInterval(MyMar)}//鼠标经过时清除定时器达到滚动停止的目的demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)} //鼠标移开时重设定时器--></script><DIV id=demo_1 style="OVERFLOW: hidden; HEIGHT: 136px"><DIV id=demo1_1><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div></DIV><DIV id=demo2_1></DIV></DIV><SCRIPT>var speed=25demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetWidth-demo.scrollLeft<=0)demo.scrollLeft-=demo1.offsetWidthelse{demo.scrollLeft++}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function() {clearInterval(MyMar)} demo.onmouseout=function(){MyMar=setInterval(Marquee,speed)} </SCRIPT> 其中<div id=gleft>这里的gleft的样式你自己定义下就OK 了。
教你如何实现DIV的图片无缝滚动效果
教你如何实现DIV的图片无缝滚动效果在网站制作和站长进行网站维护的时候,经常会想使用滚动图片来达到某种效果,现在我们来教大家如何实现,下面由洛阳蓝点科技技术员整理发布:先了解一下对象的几个的属性:innerHTML:设置或获取位于对象起始和结束标签内的HTMLscrollHeight: 获取对象的滚动高度。
scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离scrollWidth:获取对象的滚动宽度offsetHeight:获取对象相对于版面或由父坐标offsetParent 属性指定的父坐标的高度offsetLeft:获取对象相对于版面或由offsetParent 属性指定的父坐标的计算左侧位置offsetTop:获取对象相对于版面或由offsetTop 属性指定的父坐标的计算顶端位置offsetWidth:获取对象相对于版面或由父坐标offsetParent 属性指定的父坐标的宽度图片上无缝滚动<style type="text/css"><!--#demo {background: #FFF;overflow:hidden;border: 1px dashed #CCC;height: 100px;text-align: center;float: left;}#demo img {border: 3px solid #F2F2F2;display: block;}--></style>向上滚动<div id="demo"><div id="demo1"><a href="#"><img src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img"_fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a></div><div id="demo2"></div></div><script><!--var speed=10; //数字越大速度越慢var tab=document.getElementById("demo");var tab1=document.getElementById("demo1");var tab2=document.getElementById("demo2");tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2function Marquee(){if(tab2.offsetTop-tab.scrollTop<=0)//当滚动至demo1与demo2交界时tab.scrollTop-=tab1.offsetHeight //demo跳到最顶端else{tab.scrollTop++}}var MyMar=setInterval(Marquee,speed);tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器--></script>图片下无缝滚动<style type="text/css"><!--#demo {background: #FFF;overflow:hidden;border: 1px dashed #CCC;height: 100px;text-align: center;float: left;}#demo img {border: 3px solid #F2F2F2;display: block;}</style>向下滚动<div id="demo"><div id="demo1"><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a></div><div id="demo2"></div></div><script><!--var speed=10; //数字越大速度越慢var tab=document.getElementById("demo");var tab1=document.getElementById("demo1");var tab2=document.getElementById("demo2");tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2tab.scrollTop=tab.scrollHeightfunction Marquee(){if(tab1.offsetTop-tab.scrollTop>=0)//当滚动至demo1与demo2交界时tab.scrollTop+=tab2.offsetHeight //demo跳到最顶端else{tab.scrollTop--}}var MyMar=setInterval(Marquee,speed);tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器--></script>图片左无缝滚动<style type="text/css"><!--#demo {background: #FFF;overflow:hidden;border: 1px dashed #CCC;width: 500px;}#demo img {border: 3px solid #F2F2F2;}#indemo {float: left;width: 800%;}#demo1 {float: left;}#demo2 {float: left;}--></style>向左滚动<div id="demo"><div id="indemo"><div id="demo1"><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img"src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a></div><div id="demo2"></div></div></div><script><!--var speed=10; //数字越大速度越慢var tab=document.getElementById("demo");var tab1=document.getElementById("demo1");var tab2=document.getElementById("demo2");tab2.innerHTML=tab1.innerHTML;function Marquee(){if(tab2.offsetWidth-tab.scrollLeft<=0)tab.scrollLeft-=tab1.offsetWidthelse{tab.scrollLeft++;}}var MyMar=setInterval(Marquee,speed);tab.onmouseover=function() {clearInterval(MyMar)};tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};--></script>图片右无缝滚动<style type="text/css"><!--#demo {background: #FFF;overflow:hidden;border: 1px dashed #CCC;width: 500px;}#demo img {border: 3px solid #F2F2F2;}#indemo {float: left;width: 800%;}#demo1 {float: left;}#demo2 {float: left;}--></style>向右滚动<div id="demo"><div id="indemo"><div id="demo1"><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a><a href="#"><img _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" _fcksavedurl=""#"><img" src="/images/logo.jpg" border="0" /></a></div><div id="demo2"></div></div></div><script><!--var speed=10; //数字越大速度越慢var tab=document.getElementById("demo");var tab1=document.getElementById("demo1");var tab2=document.getElementById("demo2");tab2.innerHTML=tab1.innerHTML;function Marquee(){if(tab.scrollLeft<=0)tab.scrollLeft+=tab2.offsetWidthelse{tab.scrollLeft--}}var MyMar=setInterval(Marquee,speed);tab.onmouseover=function() {clearInterval(MyMar)};tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};--></script>本篇文章来源于蓝点科技() 原文出处:/2008/product.asp?i=5&id=297。
html图片无缝滚动代码(向左滚动)
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="_left1" valign="top" align="center">
function Marquee3(){
if(_left2.offsetWidth-_left.scrollLeft<=0)
_left.scrollLeft-=_left1.offsetWidth
else{
_left.scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
_left.onmouseover=function() {clearInterval(MyMar3)}
_left.onmouseout=function() {MyMaห้องสมุดไป่ตู้3=setInterval(Marquee3,speed)}
</script>
<td><a href=""><img src="/logo.gif" border=0></a></td>
<td><a href=""><img src="/logo.gif" border=0></a></td>
前端学习----实现跑马灯的三种方式
前端学习----实现跑马灯的三种⽅式参考博客:⽂中提出了三种实现跑马灯的⽅式,分别是1.利⽤js实现2.利⽤html标签实现3.利⽤css实现⽂中也给出了3种⽅法优劣的⽐较,这⾥不再赘述1.利⽤js实现跑马灯<div id="move">三玖是我⽼婆,春⽇野穹是我妹妹</div>#move{position: absolute;width: 230px;background: grey;color:white;}window.onload=function(){var move=document.getElementById('move');move.style.right='-230px';moveRight();}function moveRight(){if(parseInt(move.style.right)>screen.width) {move.style.right='0';}move.style.right=parseInt(move.style.right)+3+'px';setTimeout(moveRight,10);}这个就是利⽤js操控dom元素的属性利⽤setTimeout调⽤⾃⼰不断改变right的⼤⼩进⾏移动2.利⽤html 实现这个是利⽤marquee标签实现3.利⽤css 实现//html<div id="move"><div id="cont">三玖是我⽼婆,春⽇野穹是我妹妹</div></div>// css#move{position: relative;width: 230px;height: 40px;background: grey;color:white;}#cont{position:absolute;left: 0;right: 0;transition: left 10s linear;}//jswindow.onload=function(){var cont=document.getElementById('cont');cont.style.left="-230px";}利⽤transition实现跑马灯效果css实现⽆缝滚动//html<div id="move"><div id="cont"><div class="text">1三玖是我⽼婆,春⽇野穹是我妹妹</div><div class="text">2三玖是我⽼婆,春⽇野穹是我妹妹</div></div></div>//css*{padding: 0;margin:0;}#move{position: relative;width: 230px;height: 20px;background: grey;color:white;overflow: hidden;}#cont{width: 200%;height: 20px;position:absolute;left: 0;top: 0;animation:5s move infinite linear;}#cont .text{display: inline-block;float: left;width: 50%;height: 20px;}@keyframes move{0%{left: 0;}100%{left: -100%;}}利⽤animation实现⽆缝滚动当然实际上是利⽤了2条相同的数据。
关于网页上图片无缝滚动的一些思路
关于网页上图片无缝滚动的一些思路从现在的一些常见网站上,无缝滚动的例子用得非常普遍,可以说很常见,也比较实用,下面我们就来简单看看,具体的一些想法怎么实现的:先简单来看一下原理:首先我们看到网页上一组图片不停滚动,一次循环之后又从第一张开始,其实简单的思路是:我们设置两组图片,当第一组图片滚动到结尾时,对应的第一组图片又瞬间拉回到起始位置。
当图片向另外一个方向滚动时,当后面一组图片滚动到结尾时:也是瞬间拉回到开头。
下面我们简单来看一下代码:<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style type="text/css">*{ margin: 0;padding: 0; } //页面的简单布局#div1{ width: 600px;height: 120px;border: 1px solid #ccc; margin: 10px auto;position: relative;overflow:hidden;} #div1 ul{ list-style-type: none;height:120px;position: absolute;left: 0;top: 0; }#div1 ul li{float: left;width: 100px;height: 100px;padding: 10px;}</style><script type="text/javascript">window.onload = function(){var oUl = document.getElementById("ul1");var oLi = oUl.getElementsByTagName('li');var timer = null; //声明一个接受定时器返回值的变量,初始值为空var iSpeed = -2;oUl.style.width = (oLi.length)*oLi[0].offsetWidth+'px'; //动态的添加UL的长度,这样可以适应布局timer=setInterval(function(){if(oUl.offsetLeft<-oUl.offsetWidth/2){ //首先向左滚动,如果滚到一半,此时left应该是-oUl.offsetWidth/2,我们就将他拉回来到起始的位置oUl.style.left = 0+'px';}if(oUl.offsetLeft>0){oUl.style.left = -oUl.offsetWidth/2+'px'; //同理向右跑到一半,原理一样,就拉回来}oUl.style.left = oUl.offsetLeft+iSpeed+'px';},30);oUl.onmouseover = function(){ //鼠标移入到图片上时,就停止运动clearInterval(timer);}oUl.onmouseout = function(){timer=setInterval(function(){if(oUl.offsetLeft<-oUl.offsetWidth/2){ //鼠标移出时,又开始运动oUl.style.left = 0+'px';}if(oUl.offsetLeft>0){oUl.style.left = -oUl.offsetWidth/2+'px'; //向右跑到一半,就拉回来}oUl.style.left = oUl.offsetLeft+iSpeed+'px';},30);}}</script></head><body><div id="div1"><ul id="ul1"> //这里我们设置了两组图片<li><img src="img/宁静的海1.jpg"></li><li><img src="img/就这样1.jpg"></li><li><img src="img/宁静1.jpg"></li><li><img src="img/bus1.jpg"></li><li><img src="img/cry1.jpg"></li><li><img src="img/宁静的海1.jpg"></li><li><img src="img/就这样1.jpg"></li><li><img src="img/宁静1.jpg"></li><li><img src="img/bus1.jpg"></li><li><img src="img/cry1.jpg"></li></ul></div></body></html>当然我么可以简化代码:function startMove(){timer=setInterval(function(){if(oUl.offsetLeft<-oUl.offsetWidth/2){ //鼠标移出时,又开始运动oUl.style.left = 0+'px';}if(oUl.offsetLeft>0){oUl.style.left = -oUl.offsetWidth/2+'px'; //向右跑到一半,就拉回来}oUl.style.left = oUl.offsetLeft+iSpeed+'px';},30);}将这段重复代码写成一个函数,后面直接调用即可。
js实现从右往左匀速显示图片(无缝轮播)
js实现从右往左匀速显⽰图⽚(⽆缝轮播)本⽂实例为⼤家分享了js实现从右往左匀速显⽰图⽚的具体代码,供⼤家参考,具体内容如下前⾔:匀速显⽰图⽚,⼀般⽤于重复显⽰公司活动系列图⽚背景图⽚:<!DOCTYPE html><html lang="zh"><head><meta charset="UTF-8" /><style type="text/css">*{margin: 0;padding: 0;}.sider{height: 300px;background: url(zbg.png)no-repeat;background-size: 100% 100%;box-sizing: border-box;position: relative;overflow: hidden;}.box{position: absolute;top: 48px;left: 0;height: 300px;width: 10000px;}.uls,.uls2{display: inline-block;}.uls li,.uls2 li{display: inline-block;width: 320px;height: 206px;margin-right: 10px;background: red;}.uls li img,.uls2 li img{width: 100%;height: 100%;}</style></head><body><div class="sider"><div class="box"><ul class="uls"><li>这是图⽚1</li><li>这是图⽚2</li><li>这是图⽚3</li><li>这是图⽚4</li><li>这是图⽚5</li><li>这是图⽚6</li></ul><ul class="uls2"><ul></div></div><script src="jquery.min.js"></script><script>$(function(){var i=0;var sizess = $(".uls li").length;var sizesspx = sizess*330;var clone = $(".uls").html();$(".uls2").html(clone);var t=setInterval(moveL,30);// 封装的动画函数function moveL(){i++;var sizess = $(".uls li").length;if(i>sizesspx){$(".box").css({left:0});i=0}$(".box").css({left:-i+'px'});}})</script></body></html>运⾏效果:精彩专题分享:以上就是本⽂的全部内容,希望对⼤家学习Jquery程序设计有所帮助。
常用js效果一:div+css图片上下左右滚动代码
常用js效果一:div+css图片上下左右滚动代码图片滚动经常在网页里面用到,高手们都是自己来写,我不是高手,所以高手们写了,我就搬来用了,偷偷懒,“常用js效果一:div+css图片上下左右滚动代码”这个也是在网上找的,这个被转载了很多次,测试了下,ie6,7,8还有火狐都能兼容的。
还有demo哦!!需要的可以下载哈。
这是向上滚动的:XML/HTML代码1.<style type="text/css">2.<!--3.#demo {4.background: #FFF;5.overflow:hidden;6.border: 1px dashed #CCC;7.height: 300px;8.text-align: center;9.float: left;10.}11.#demo img {12.border: 3px solid #F2F2F2;13.display: block;14.}15.-->16.</style>17.向上滚动18.<div id="demo">19.<div id="demo1">20.<a href="#"><img src="upload/2011/11/2011111114 43365181.gif" border="0" /></a>21.<a href="#"><img src="upload/2011/11/2011111114 43365181.gif" border="0" /></a>22.<a href="#"><img src="upload/2011/11/2011111114 43365181.gif" border="0" /></a>23.<a href="#"><img src="upload/2011/11/201111111443365181.gif" border="0" /></a>24.<a href="#"><img src="upload/2011/11/2011111114 43365181.gif" border="0" /></a>25.</div>26.<div id="demo2"></div>27.</div>28.<script>29.<!--30.var speed=10; //数字越大速度越慢31.var tab=document.getElementById("demo");32.var tab1=document.getElementById("demo1");33.var tab2=document.getElementById("demo2");34.tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo235.function Marquee(){36.if(tab2.offsetT op-tab.scrollTop<=0)//当滚动至demo1与demo2交界时37.tab.scrollTop-=tab1.offsetHeight //demo跳到最顶端38.else{39.tab.scrollTop++40.}41.}42.var MyMar=setInterval(Marquee,speed);43.tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的44.tab.onmouseout=function() {MyMar=setInterval(Marq uee,speed)};//鼠标移开时重设定时器45.-->46.</script>演示地址:这是向下滚动的:XML/HTML代码1.<style type="text/css">2.<!--3.#demo {4.background: #FFF;5.overflow:hidden;6.border: 1px dashed #CCC;7.height: 200px;8.text-align: center;9.float: left;10.}11.#demo img {12.border: 3px solid #F2F2F2;13.display: block;14.}15.-->16.</style>17.向下滚动18.<div id="demo">19.<div id="demo1">20.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>21.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>22.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>23.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>24.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>25.</div>26.<div id="demo2"></div>27.</div>28.<script>29.<!--30.var speed=10; //数字越大速度越慢31.var tab=document.getElementById("demo");32.var tab1=document.getElementById("demo1");33.var tab2=document.getElementById("demo2");34.tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo235.tabtab.scrollTop=tab.scrollHeight36.function Marquee(){37.if(tab1.offsetT op-tab.scrollTop>=0)//当滚动至demo1与demo2交界时38.tab.scrollTop+=tab2.offsetHeight //demo跳到最顶端39.else{40.tab.scrollTop--41.}42.}43.var MyMar=setInterval(Marquee,speed);44.tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的45.tab.onmouseout=function() {MyMar=setInterval(Marq uee,speed)};//鼠标移开时重设定时器46.-->47.</script>演示地址:这是向左滚动的:XML/HTML代码1.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xht ml1-transitional.dtd">2.<html xmlns="/1999/xhtml">3.<head>4.<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />5.<title>无标题文档</title>6.</head>7.<body>8.<style>9..scroll_div {width:600px; height:62px;margin:0 auto; overfl ow: hidden; white-space: nowrap; background:#ffffff;}10..scroll_div img {width:120px;height:60px;border: 0;mar gin: auto 8px; border:1px #efefef solid;}11.#scroll_begin, #scroll_end, #scroll_begin ul, #scroll_end ul, #scroll_begin ul li, #scroll_end ul li{display:inline;}12.</style>13.<script language="javascript">14.function ScrollImgLeft(){15.var speed=2016.var scroll_begin = document.getElementById("scroll_b egin");17.var scroll_end = document.getElementById("scroll_end ");18.var scroll_div = document.getElementById("scroll_div") ;19.scroll_end.innerHTML=scroll_begin.innerHTML20.function Marquee(){21.if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0)22.scroll_div.scrollLeft-=scroll_begin.offsetWidth23.else24.scroll_div.scrollLeft++25.}26.var MyMar=setInterval(Marquee,speed)27.scroll_div.onmouseover=function() {clearInterval(MyM ar)}28.scroll_div.onmouseout=function() {MyMar=setInterval (Marquee,speed)}29.}30.</script>31.<h2 align="center">向左滚动</h2>32.<div style="text-align:center">33.<div class="sqBorder">34.<!--#####滚动区域#####-->35.<div id="scroll_div" class="scroll_div">36.<div id="scroll_begin">37.<ul>38.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>39.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>40.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>41.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>42.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>43.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>44.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>45.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>46.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>47.<li><a href="upload/2011/11/201111111446056115. gif" /></a></li>48.</ul>49.</div>50.<div id="scroll_end"></div>51.</div>52.<!--#####滚动区域#####-->53.</div>54.<script type="text/javascript">ScrollImgLeft();</script >55.</div>56.<!--//向左滚动代码结束-->57.</body></html>演示地址:这是向右滚动的代码:XML/HTML代码1.<style type="text/css">2.<!--3.#demo {4.background: #FFF;5.overflow:hidden;6.border: 1px dashed #CCC;7.width: 500px;8.}9.#demo img {10.border: 3px solid #F2F2F2;11.}12.#indemo {13.float: left;14.width: 800%;15.}16.#demo1 {17.float: left;18.}19.#demo2 {20.float: left;21.}22.-->23.</style>24.向右滚动25.<div id="demo">26.<div id="indemo">27.<div id="demo1">28.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>29.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>30.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>31.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>32.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>33.<a href="#"><img src="upload/2011/11/2011111413 35356083.gif" border="0" /></a>34.</div>35.<div id="demo2"></div>36.</div>37.</div>38.<script>39.<!--40.var speed=10; //数字越大速度越慢41.var tab=document.getElementById("demo");42.var tab1=document.getElementById("demo1");43.var tab2=document.getElementById("demo2");44.tab2.innerHTML=tab1.innerHTML;45.function Marquee(){46.if(tab.scrollLeft<=0)47.tab.scrollLeft+=tab2.offsetWidth48.else{49.tab.scrollLeft--50.}51.}52.var MyMar=setInterval(Marquee,speed);53.tab.onmouseover=function() {clearInterval(MyMar)};54.tab.onmouseout=function() {MyMar=setInterval(Marq uee,speed)};55.-->56.</script>。
使用JS实现图片轮播滚动跑马灯效果
使⽤JS实现图⽚轮播滚动跑马灯效果 我的第⼀篇⽂章、哈哈、有点⼩鸡冻。
之前在百度搜索“图⽚轮播”、“图⽚滚动”,结果都是那种可以左右切换的。
也是我们最常见的那种。
可能是搜索关键字的问题吧。
如图:教程效果图:教程开始:HTML代码:1<body>2<div id="div1">3<div id="div4">4<div id="div2">5<img src="img/1.jpg" alt="图⽚1"/>6<img src="img/2.jpg" alt="图⽚2"/>7<img src="img/3.jpg" alt="图⽚3"/>8<img src="img/4.jpg" alt="图⽚4"/>9</div>10<div id="div3"></div><!--这个容器是⽤来防⽌图⽚滚动时会出现空⽩的区域-->11</div>12</div>13</body>CSS代码:1<style type="text/css">2 div,img{3 margin:0;4 padding:0;5 }6 img{7 float:left;8 height:100px;9 width:150px;10 }11 #div1{12 width:500px;13 height:100px;14 overflow: hidden;15 border:solid blue 2px;16 }17 #div2,#div3{18 float:left;19 }23 #div4{24 width:500%;/*这个属性很重要让容器有⾜够的宽度实现滚动*/25 float:left;26 }27 </style>JavaScript代码:1 <script type="text/javascript">2 window.onload=function(){3var v1=document.getElementById('div1');4var v2=document.getElementById('div2');5var v3=document.getElementById('div3');67 v3.innerHTML= v2.innerHTML;//将v2容器⾥⾯的图⽚插⼊到v3容器⾥⾯使其空⽩区域被遮住。
HTMl中marquee标签实现无缝滚动跑马灯效果
HTMl中marquee标签实现⽆缝滚动跑马灯效果<marquee>标签,它是成对出现的标签,⾸标签<marquee>和尾标签</marquee>之间的内容就是滚动内容。
<marquee>标签的属性主要有behavior、bgcolor、direction、width、height、hspace、vspace、loop、scrollamount、scrolldelay等,它们都是可选的。
今天在做微信端的⼤转盘抽奖时,想把所有⽤户的抽奖记录做成⽆缝滚动的效果,⽆奈我的js功底太差,⼀时想不出实现的⽅法,便百度各种相似效果。
但⽆意中发现了⼀个html标签——<marquee></marquee>可以实现多种滚动效果,⽆需js控制。
使⽤marquee标签不仅可以滚动⽂字,也可以滚动图⽚,表格等,⽽且使⽤起来⽅便快捷,真的为我节省了不少时间。
marquee标签不是HTML3.2的⼀部分,并且只⽀持MSIE3以后内核,所以如果你使⽤⾮IE内核浏览器(如:Netscape)可能⽆法看到下⾯⼀些很有意思的效果,该标签是个容器标签。
⼀、marquee标签的⼏个重要属性:1.direction:滚动⽅向(包括4个值:up、down、left、right)说明:up:从下向上滚动;down:从上向下滚动;left:从右向左滚动;right:从左向右滚动。
语法:<marquee direction="滚动⽅向">...</marquee>2.behavior:滚动⽅式(包括3个值:scroll、slide、alternate)说明:scroll:循环滚动,默认效果;slide:只滚动⼀次就停⽌;alternate:来回交替进⾏滚动。
语法:<marquee behavior="滚动⽅式">...</marquee>3.scrollamount:滚动速度(滚动速度是设置每次滚动时移动的长度,以像素为单位)语法:<marquee scrollamount="5">...</marquee>4.scrolldelay:设定滚动两次之间的延迟时间,值⼤了会有⼀步⼀停顿的效果(设置滚动的时间间隔,单位是毫秒)语法:<marquee scrolldelay="100">...</marquee>5.loop:设定滚动循环的次数(默认值是-1,滚动会不断的循环下去)语法:<marquee loop="2">...</marquee><marquee loop="-1" bgcolor="#CCCCCC">我会不停地⾛。
网页效果:js或jQuery实现图片左右无缝滚动
网页效果:js或jQuery实现图片左右无缝滚动网页效果:js或jQuery实现图片向左无缝滚动一、效果思路1、设置一个外层div达到超出隐藏的效果2、滚动元素需要克隆一个,为了达到第一个滚动元素超出时,像是跑到最右边重新滚动开始3、设置定时重复效果,使得元素循环滚动,通过不断改变scrollLeft达到滚动的目的4、鼠标悬停效果Html布局效果图:二、Js实现代码Html:Css:{margin:0;padding:0;}#div1{width:420px;height:110px;margin:0auto;overflow:hidd en;border:1pxsolidblack;padding:5px0px;margin-top:50px;}.div2{width:300%;}#demo1,#demo2{float:left;}.div2ulli{float:left;list-style:none;border:1pxsolidred;margin:04px;}Js:代码解释:Marquee():js函数,控制滚动以及滚动元素滚动完成时重新将scrollLeft归零offsetWidth:获取元素宽度setInterval:定时执行函数onmouseover、onmouseout鼠标放在上面和离开是的效果注意:宽高都写在样式表里,就比如#id{width:120px;}。
这中情况通过#id.style.width拿不到宽度,而通过#id.offsetWidth才可以获取到宽度。
若是想通过#id.style.width获取元素宽度值,需要将宽和高是写在行内中,比如style="width:120px;"三、jQuery实现Html:Css:{margin:0;padding:0;}#div1{width:420px;height:110px;margi n:0auto;overflow:hidden;border:1pxsolidblack;padding:5px0px;margin-top:50px;}.div2{width:300%;}#demo1,#demo2{float:left;}.div2ulli{float:left;list-style:none;border:1pxsolidred;margin:04px;}Jquery:解释:clone():克隆元素append():追加到元素后面Hover(function1,function1):function1鼠标放在上面执行的函数,function1鼠标离开执行的函数trigger("mouseleave"):事件触发mouseleave,可理解为页面加载就执行clearInterval:清除定时setInterval:创建定时滚动效果图:。
图片轮播(左右切换)--JS原生和jQuery实现
图⽚轮播(左右切换)--JS原⽣和jQuery实现图⽚轮播(左右切换)--js原⽣和jquery实现左右切换的做法基本步骤跟上⼀篇⽂章类似,只不过修改了⼀些特定的部分(1)⾸先是页⾯的结构部分对于我这种左右切换式1.⾸先是个外围部分(其实也就是最外边的整体wrapper)2.接着就是你设置图⽚轮播的地⽅(也就是⼀个banner吧)3.然后是⼀个图⽚组(可以⽤新的div 也可以直接使⽤ ul-->li形式)4.然后是图⽚两端的左箭头和右箭头5.然后是⼀个透明背景层,放在图⽚底部6.然后是⼀个图⽚描述info层,放在透明背景层的左下⾓(div 或 ul-->li)7.然后是⼀个按钮层,⽤来定位图⽚组的index吧,放在透明背景层的右下⾓(div 或 ul-->li)由此,可以先构造出html结构<div id="wrapper"><!-- 最外层部分 --><div id="banner"><!-- 轮播部分 --><ul class="imgList"><!-- 图⽚部分 --><li><a href="#"><img src="./img/test1.jpg" width="400px" height="200px" alt="puss in boots1"></a></li><li><a href="#"><img src="./img/test2.jpg" width="400px" height="200px" alt="puss in boots2"></a></li><li><a href="#"><img src="./img/test3.jpg" width="400px" height="200px" alt="puss in boots3"></a></li><li><a href="#"><img src="./img/test4.jpg" width="400px" height="200px" alt="puss in boots4"></a></li><li><a href="#"><img src="./img/test5.jpg" width="400px" height="200px" alt="puss in boots5"></a></li></ul><img src="./img/prev.png" width="20px" height="40px" id="prev"><img src="./img/next.png" width="20px" height="40px" id="next"><div class="bg"></div><!-- 图⽚底部背景层部分--><ul class="infoList"><!-- 图⽚左下⾓⽂字信息部分 --><li class="infoOn">puss in boots1</li><li>puss in boots2</li><li>puss in boots3</li><li>puss in boots4</li><li>puss in boots5</li></ul><ul class="indexList"><!-- 图⽚右下⾓序号部分 --><li class="indexOn">1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul></div></div>相对于之前,知识增多了两个箭头img标签(2)CSS样式部分(图⽚组的处理)跟淡⼊淡出式就不⼀样了淡⼊淡出只需要显⽰或者隐藏对应序号的图⽚就⾏了,直接通过display来设定左右切换式则是采⽤图⽚li 浮动,⽗层元素ul 总宽为总图⽚宽,并设定为有限banner宽度下隐藏超出宽度的部分然后当想切换到某序号的图⽚时,则采⽤其ul 定位 left样式设定相应属性值实现⽐如显⽰第⼀张图⽚初始定位left为0px, 要想显⽰第⼆张图⽚则需要left:-400px 处理<style type="text/css">body,div,ul,li,a,img{margin: 0;padding: 0;}ul,li{list-style: none;}a{text-decoration: none;}#wrapper{position: relative;margin: 30px auto;width: 400px;height: 200px;}#banner{position:relative;width: 400px;height: 200px;overflow: hidden;}.imgList{position:relative;width:2000px;height:200px;z-index: 10;overflow: hidden;}.imgList li{float:left;display: inline;}#prev,#next{position: absolute;top:80px;z-index: 20;cursor: pointer;opacity: 0.2;filter:alpha(opacity=20);}#prev{left: 10px;}#next{right: 10px;}#prev:hover,#next:hover{opacity: 0.5;filter:alpha(opacity=50);}.bg{position: absolute;bottom: 0;width: 400px;height: 40px;z-index:20;opacity: 0.4;filter:alpha(opacity=40);background: black;} .infoList{position: absolute;left: 10px;bottom: 10px;z-index: 30;}.infoList li{display: none;}.infoList .infoOn{display: inline;color: white;}.indexList{position: absolute;right: 10px;bottom: 5px;z-index: 30;}.indexList li{float: left;margin-right: 5px;padding: 2px 4px;border: 2px solid black;background: grey;cursor: pointer;}.indexList .indexOn{background: red;font-weight: bold;color: white;}</style>(3)页⾯基本已经构建好久可以进⾏js的处理了⼀、jQuery⽅式照常先说jq处理1.全局变量等var curIndex = 0, //当前indeximgLen = $(".imgList li").length; //图⽚总数2.⾃动切换定时器处理// 定时器⾃动变换2.5秒每次var autoChange = setInterval(function(){if(curIndex < imgLen-1){curIndex ++;}else{curIndex = 0;}//调⽤变换处理函数changeTo(curIndex);},2500);3.为左右箭头添加事件处理左箭头//左箭头滑⼊滑出事件处理$("#prev").hover(function(){//滑⼊清除定时器clearInterval(autoChange);},function(){//滑出则重置定时器autoChangeAgain();});//左箭头点击处理$("#prev").click(function(){//根据curIndex进⾏上⼀个图⽚处理curIndex = (curIndex > 0) ? (--curIndex) : (imgLen - 1);changeTo(curIndex);});右箭头//右箭头滑⼊滑出事件处理$("#next").hover(function(){//滑⼊清除定时器clearInterval(autoChange);},function(){//滑出则重置定时器autoChangeAgain();});//右箭头点击处理$("#next").click(function(){curIndex = (curIndex < imgLen - 1) ? (++curIndex) : 0;changeTo(curIndex);});其中autoChangeAgain()就是⼀个重置定时器函数//清除定时器时候的重置定时器--封装function autoChangeAgain(){autoChange = setInterval(function(){if(curIndex < imgLen-1){curIndex ++;}else{curIndex = 0;}//调⽤变换处理函数changeTo(curIndex);},2500);}其中changeTo()就是⼀个图⽚切换的处理函数function changeTo(num){var goLeft = num * 400;$(".imgList").animate({left: "-" + goLeft + "px"},500);$(".infoList").find("li").removeClass("infoOn").eq(num).addClass("infoOn");$(".indexList").find("li").removeClass("indexOn").eq(num).addClass("indexOn");}每传⼊⼀个图⽚序号,则按理进⾏goLeft4.为右下⾓的那⼏个li 按钮绑定事件处理//对右下⾓按钮index进⾏事件绑定处理等$(".indexList").find("li").each(function(item){$(this).hover(function(){clearInterval(autoChange);changeTo(item);curIndex = item;},function(){autoChangeAgain();});});jq就是这样,简便,原⽣代码量就有些多了完整代码1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xmlns="/1999/xhtml">3<head>4<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>5<title>图⽚轮播 jq(左右切换)</title>6<style type="text/css">7 body,div,ul,li,a,img{margin: 0;padding: 0;}8 ul,li{list-style: none;}9 a{text-decoration: none;}1011 #wrapper{position: relative;margin: 30px auto;width: 400px;height: 200px;}12 #banner{position:relative;width: 400px;height: 200px;overflow: hidden;}13 .imgList{position:relative;width:2000px;height:200px;z-index: 10;overflow: hidden;}14 .imgList li{float:left;display: inline;}15 #prev,16 #next{position: absolute;top:80px;z-index: 20;cursor: pointer;opacity: 0.2;filter:alpha(opacity=20);}17 #prev{left: 10px;}18 #next{right: 10px;}19 #prev:hover,20 #next:hover{opacity: 0.5;filter:alpha(opacity=50);}21 .bg{position: absolute;bottom: 0;width: 400px;height: 40px;z-index:20;opacity: 0.4;filter:alpha(opacity=40);background: black;}22 .infoList{position: absolute;left: 10px;bottom: 10px;z-index: 30;}23 .infoList li{display: none;}24 .infoList .infoOn{display: inline;color: white;}25 .indexList{position: absolute;right: 10px;bottom: 5px;z-index: 30;}26 .indexList li{float: left;margin-right: 5px;padding: 2px 4px;border: 2px solid black;background: grey;cursor: pointer;}27 .indexList .indexOn{background: red;font-weight: bold;color: white;}28</style>29</head>30<body>31<div id="wrapper"><!-- 最外层部分 -->32<div id="banner"><!-- 轮播部分 -->33<ul class="imgList"><!-- 图⽚部分 -->34<li><a href="#"><img src="./img/test1.jpg" width="400px" height="200px" alt="puss in boots1"></a></li>35<li><a href="#"><img src="./img/test2.jpg" width="400px" height="200px" alt="puss in boots2"></a></li>36<li><a href="#"><img src="./img/test3.jpg" width="400px" height="200px" alt="puss in boots3"></a></li>37<li><a href="#"><img src="./img/test4.jpg" width="400px" height="200px" alt="puss in boots4"></a></li>38<li><a href="#"><img src="./img/test5.jpg" width="400px" height="200px" alt="puss in boots5"></a></li>39</ul>40<img src="./img/prev.png" width="20px" height="40px" id="prev"> 41<img src="./img/next.png" width="20px" height="40px" id="next"> 42<div class="bg"></div><!-- 图⽚底部背景层部分-->43<ul class="infoList"><!-- 图⽚左下⾓⽂字信息部分 -->44<li class="infoOn">puss in boots1</li>45<li>puss in boots2</li>46<li>puss in boots3</li>47<li>puss in boots4</li>48<li>puss in boots5</li>49</ul>50<ul class="indexList"><!-- 图⽚右下⾓序号部分 -->51<li class="indexOn">1</li>52<li>2</li>53<li>3</li>54<li>4</li>55<li>5</li>56</ul>57</div>58</div>59<script type="text/javascript" src="./js/jquery.min.js"></script>60<script type="text/javascript">61var curIndex = 0, //当前index62 imgLen = $(".imgList li").length; //图⽚总数63// 定时器⾃动变换2.5秒每次64var autoChange = setInterval(function(){65if(curIndex < imgLen-1){66 curIndex ++;67 }else{68 curIndex = 0;69 }70//调⽤变换处理函数71 changeTo(curIndex);72 },2500);7374//左箭头滑⼊滑出事件处理75 $("#prev").hover(function(){76//滑⼊清除定时器77 clearInterval(autoChange);78 },function(){79//滑出则重置定时器80 autoChangeAgain();81 });82//左箭头点击处理83 $("#prev").click(function(){84//根据curIndex进⾏上⼀个图⽚处理85 curIndex = (curIndex > 0) ? (--curIndex) : (imgLen - 1);86 changeTo(curIndex);87 });8889//右箭头滑⼊滑出事件处理90 $("#next").hover(function(){91//滑⼊清除定时器92 clearInterval(autoChange);93 },function(){94//滑出则重置定时器95 autoChangeAgain();96 });97//右箭头点击处理98 $("#next").click(function(){99 curIndex = (curIndex < imgLen - 1) ? (++curIndex) : 0;100 changeTo(curIndex);101 });102103//对右下⾓按钮index进⾏事件绑定处理等104 $(".indexList").find("li").each(function(item){105 $(this).hover(function(){106 clearInterval(autoChange);107 changeTo(item);108 curIndex = item;109 },function(){110 autoChangeAgain();111 });112 });113114//清除定时器时候的重置定时器--封装115function autoChangeAgain(){116 autoChange = setInterval(function(){117if(curIndex < imgLen-1){118 curIndex ++;119 }else{120 curIndex = 0;121 }122//调⽤变换处理函数123 changeTo(curIndex);124 },2500);125 }126127function changeTo(num){128var goLeft = num * 400;129 $(".imgList").animate({left: "-" + goLeft + "px"},500);130 $(".infoList").find("li").removeClass("infoOn").eq(num).addClass("infoOn");131 $(".indexList").find("li").removeClass("indexOn").eq(num).addClass("indexOn");132 }133</script>134</body>135</html>View Code⼆、js 原⽣实现js原⽣⼤概也就是模拟jq的实现思路1.全局变量等var curIndex = 0, //当前indeximgArr = getElementsByClassName("imgList")[0].getElementsByTagName("li"), //获取图⽚组imgLen = imgArr.length,infoArr = getElementsByClassName("infoList")[0].getElementsByTagName("li"), //获取图⽚info组indexArr = getElementsByClassName("indexList")[0].getElementsByTagName("li"); //获取控制index组2.⾃动切换定时器处理// 定时器⾃动变换2.5秒每次var autoChange = setInterval(function(){if(curIndex < imgLen -1){curIndex ++;}else{curIndex = 0;}//调⽤变换处理函数changeTo(curIndex);},2500);同样的,有⼀个重置定时器的函数//清除定时器时候的重置定时器--封装function autoChangeAgain(){autoChange = setInterval(function(){if(curIndex < imgLen -1){curIndex ++;}else{curIndex = 0;}//调⽤变换处理函数changeTo(curIndex);},2500);}3.因为有⼀些class呀,所以来⼏个class函数的模拟也是需要的//通过class获取节点function getElementsByClassName(className){var classArr = [];var tags = document.getElementsByTagName('*');for(var item in tags){if(tags[item].nodeType == 1){if(tags[item].getAttribute('class') == className){classArr.push(tags[item]);}}}return classArr; //返回}// 判断obj是否有此classfunction hasClass(obj,cls){ //class位于单词边界return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));}//给 obj添加classfunction addClass(obj,cls){if(!this.hasClass(obj,cls)){obj.className += cls;}}//移除obj对应的classfunction removeClass(obj,cls){if(hasClass(obj,cls)){var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');obj.className = obj.className.replace(reg,'');}}4.要左右切换,就得模拟jq的animate-->left .我的思路就是动态地设置element.style.left 进⾏定位。
js实现图片无缝循环跑马灯
js实现图⽚⽆缝循环跑马灯html 代码<div class="myls-out-div" style="overflow: hidden;"><ul id="mylspaomadeng" class="myls-ul" ><li class="myls-li"><img class="myls-img" src="img/indexImg/myls1.png" /></li><li class="myls-li"><img class="myls-img" src="img/indexImg/myls2.png" /></li><li class="myls-li"><img class="myls-img" src="img/indexImg/myls3.png" /></li><li class="myls-li"><img class="myls-img" src="img/indexImg/myls4.png" /></li></ul></div>css.myls-out-div {width: 100%;height: 212px;background-color: #fafafa;float: left;overflow: hidden;}.myls-img {height: 100%;}.myls-ul{float: left;height: 100%;position: relative;margin: 0px;padding: 0px;}.myls-li{list-style: none;display: inline-block;float: left;padding-right: 15px;padding-top: 15px;padding-bottom: 15px;height: 100%;}js代码function mylsRunHorseLight() {if (mylsTimer != null) {clearInterval(mylsTimer);}var oUl = document.getElementById("mylspaomadeng"); if(oUl != null){oUl.innerHTML += oUl.innerHTML;oUl.innerHTML += oUl.innerHTML;oUl.innerHTML += oUl.innerHTML;var lis = oUl.getElementsByTagName('li');var lisTotalWidth = 0;var resetWidth = 0;for (var i = 0; i < lis.length; i++) {lisTotalWidth += lis[i].offsetWidth;}for (var i = 1; i <= lis.length / 4; i++) {resetWidth += lis[i].offsetWidth;}oUl.style.width = lisTotalWidth + 'px';var left = 0;mylsTimer = setInterval(function() {left -= 1;if (left <= -resetWidth) {left = 0;}oUl.style.left = left + 'px';}, 20)$("#mylspaomadeng").hover(function() {clearInterval(mylsTimer);}, function() {clearInterval(mylsTimer);mylsTimer = setInterval(function() {left -= 1;if (left <= -resetWidth) {left = 0;}oUl.style.left = left + 'px';}, 20);})}}注意事项正常来说,宽度是⾃动获取进⾏计算的。
div+css跑马灯
1.从右到左代码:<marquee>你的文字<marquee>2.从左到右代码:<marquee direction="right">你的文字</marquee>3.碰壁反弹代码:<marquee behavior="alternate">你的文字</marquee>4.从下往上代码:<marquee direction="up">你的文字</marquee>5.从上往下代码:<marquee direction="down">你的文字</marquee>6.上下反弹代码:<marquee direction="up" behavior="alternate">你的文字</marquee> 7.上下弧度抛物线代码:<marquee behavior="alternate" direction="up" width="80%"><marqu ee direction="right">你的文字</marquee></marquee>8.上下左右碰壁代码:<marquee behavior="alternate" direction="up" width="80%"><marqu ee direction="right" behavior="alternate">你的文字</marquee></marquee> 9.字不动箭头碰字代码:<marquee behavior="alternate" width="10%">>></marquee>你的文字<marquee behavior="alternate" width="10%"><<</marquee>10.字不动箭头远离字代码:<marquee behavior="alternate" width="10%">>></marquee>你的文字<marquee behavior="alternate" width="10%"><<</marquee>11.从左到右加底色代码:<font color="#0000FF"><marquee direction="left" style="background: #FFCC00">你的文字</marquee></font>12.从左到右加外诓代码:<marquee style="border:1px dotted #CC0066 ">你的文字</marquee> 13.滚动字代码:<marquee behavior="alternate"><marquee width="150">你的文字</ma rquee></marquee>14.从下往上飘代码:<marquee behavior=alternate direction=up scrollamount=2 scrolldelay =65 height=80 style="Text-align;filter:wave(add=0,phase=1, freq=1,strengt h=15,color=.FFFFFF)"><center>第一行字<BR />第二行字</center></marque e>15.多嵌套字代码:<table bgcolor="#FFFFFF"> <tr><td width="1" valign="top" > <marquee direction="down" behavior="alternate" scrollamount=1 height="60"> <marque e direction="right" scrollamount=4 behavior="alternate" width="468"> 你的文字1</marquee> </marquee> </td> <td width="468"> <marquee direction=" up" behavior="alternate" scrollamount=1 height="60"> <marquee direction="left" scrollamount=4 behavior="alternate" width="468"> 你的文字2</marquee> </marquee> </td></tr></table>。
vue实现无缝轮播效果(跑马灯)
vue实现⽆缝轮播效果(跑马灯)本⽂实例为⼤家分享了vue实现⽆缝轮播效果的具体代码,供⼤家参考,具体内容如下1.⾸先创建两个vue组件Sweiper.vue和SweiperItem.vue;2.将两个组件引⼊页⾯,Sweiper.vue中⽤v-model传参(v-model 其实是语法糖,默认属性value和默认事件input);代码中我是通过v-model的selcted将值传给Sweiper(⼦组件),⾃动轮播时⼦组件再通过触发input事件将即将显⽰的值传回给⽗组件3.核⼼是要让selected的值传到SweiperItem中,与SweiperItem中的name值相等判该显⽰哪张图⽚;<template><div><Sweiper v-model="selected"><!--v-model是个语法糖,相当于value和input事件--><Sweiper-item name="item1"><div class="item"><img :src="getImg('01')" alt=""></div></Sweiper-item><Sweiper-item name="item2"><div class="item"><img :src="getImg('02')" alt=""></div></Sweiper-item><Sweiper-item name="item3"><div class="item"><img :src="getImg('03')" alt=""></div></Sweiper-item></Sweiper></div></template>这⾥的图⽚没有通过数组⽤v-for循环,⽅便⼤家看其结构形式<script>import Sweiper from "../components/Sweiper.vue";import SweiperItem from "../components/SweiperItem.vue";export default {name: "mySweiper",components: {Sweiper,SweiperItem},data() {return {selected: "item1",//默认第⼀张}},methods:{getImg(url){return "img/"+url+".jpg"},},mounted(){/*setInterval(()=>{this.selected="item2"},3000)此时因为mounted只执⾏⼀次,所以还是不变,需要在Sweiper写⼀个watch监听}*/这⼀步注释是因为换到Sweiper组件中写了}</script><style >.item{/*border: 1px solid black;*/}.item>img{width: 100%;/*height: 0.1rem;*/}</style>Sweiper.vue<template><div class="Sweiper"><slot></slot></div></template><script>export default {name: "Sweiper",data() {return{current:''}},props:{value:{type:String,default:""},},mounted(){//⾃动轮播时查找name值⽤indexOf的⽅法遍历出当前轮播的下表 s=this.$children.map(child=>{return });this. showImg();this. paly()},methods:{showImg(){this.current=this.value||this.$children[0].name;//当前实例的直接⼦组件this.$children.map(vm=>{vm.selected=this.current})},paly(){//每次轮播把图⽚做调整this.timer=setInterval(()=>{//indexOf返回某个指定字符串⾸次出现的位置const index=s.indexOf(this.current);let newIndex=index+1;//严谨⼀点if (newIndex===s.length){newIndex=0;}this.$emit("input",s[newIndex])},3000)}},watch:{//监听value值,发⽣变化就改变selectedvalue(){this. showImg()}},beforeDestroy() {//实列销毁前clearInterval(this.timer)}};</script><style>.Sweiper{/*border: 1px solid black;*/width: 100%;height: 4rem;overflow: hidden;margin: 0 auto;position: relative;}</style>SweiperItem.vue<template><transition><div class="Sweiper-item" v-show="isShow"><slot></slot></div></transition></template><script>export default {name:"SweiperItem",data(){return{selected:""}},props:{name:{type:String,required:true},},mounted(){},computed:{isShow(){return this.selected===;}}};</script><style>.v-enter-active,.v-leave-active{transition: all 1s linear;}.v-leave-to{transform:translate(-100%);}.v-enter{transform: translate(100%);}.v-enter-active{position: absolute;top:0;left: 0;}</style>以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
div实现向左右无缝滚动图片效果(跑马灯)div+css学习笔记22(用div实现向左无缝滚动图片效果)JavaScript实现走马灯效果[无缝连接、循环滚动] 无缝跑马灯效果以下代码在IE6、Firefox+Win2k环境下测试通过网页走马灯连续循环滚动废话少说,代码贴出来:<div id="imgmarquee" style="OVERFLOW: hidden; WIDTH: 580px; align: left; background-color:#0099CC;"> <div style="width:1200px"><!--id="marquePic1"里面的宽度一定要大于id="imgmarquee"的宽度才能看到效果width:600px;>WIDTH: 580px;大的div宽度要为span的两倍才可以,不然会换行width:1200px zdz的作品,流风的作品--> <span id="marquePic1"style="width:600px; background-color:#990033;"><img src="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> <imgsrc="../images/dialog/4.gif" /> </span><span id="marquePic2"style="width:600px;background-color:#990033;"></sp an> </div></div> <scripttype="text/javascript"> var imgmarquee = document.getElementById('imgmarquee');var marquePic2 = document.getElementById('marquePic2');var marquePic1 =document.getElementById('marquePic1');var speed=10;//控制移动的速度,数越大越慢marquePic2.innerHTML=marquePic1.innerHTML;//把marquePic1的内容复制到marquePic2里面function Marquee(){ if(imgmarquee.scrollLeft>=marquePic1.scro llWidth){ imgmarquee.scrollLeft=0;}else{ //demo.scrollLeft+ +; imgmarquee.scrollLeft++; }} varmarqueetemp=setInterval(Marquee,speed); imgmarquee.onmouseover=function(){clearInterval(marqueetemp)} //鼠标移到上面停止并清除计数imgmarquee.onmouseout=function() {marqueetemp=setInterval(Marquee,speed)} //鼠标离开重新计数</script>------------参考资料(向右,向上,向下代码同理,只是控制的js不同而已,把下面的id改成对应的就ok了)------------向右------------<scriptlanguage="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //数值越大滚动速度越慢demo2.innerHTML =demo1.innerHTML;demo.scrollLeft =demo.scrollWidth;functionMarquee(){ if(demo.scrollLeft<=0)demo.scrollLeft+=demo2.offsetWidthelse{ demo.scrollLeft-- }}var MyMar = setInterval(Marquee,speed)demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)}--></script>-------------向下-------------<scriptlanguage="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //数值越大滚动速度越慢demo2.innerHTML =demo1.innerHTML;demo.scrollTop =demo.scrollHeight;functionMarquee(){ if(demo1.offsetTop-demo.scrollTop>=0) demo.scrollTop+=demo2.offsetHeightelse{ demo.scrollTop-- }}var MyMar = setInterval(Marquee,speed);demo.onmouseover = function(){clearInterval(MyMar)}demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)}--></script>-----------向上-----------<script language="javascript"type="text/javascript"><!--var demo = document.getElementById("demo");var demo1 = document.getElementById("demo1");var demo2 = document.getElementById("demo2");var speed=10; //滚动速度值,值越大速度越慢demo2.innerHTML =demo1.innerHTML //克隆demo2为demo1function Marquee(){ if(demo2.offsetTop-demo.scrollTop<=0) //当滚动至demo1与demo2交界时demo.scrollTop-=demo1.offsetHeight //demo跳到最顶端else{ demo.scrollTop++ }}var MyMar = setInterval(Marquee,speed); //设置定时器demo.onmouseover = function(){clearInterval(MyMar)}//鼠标经过时清除定时器达到滚动停止的目的demo.onmouseout = function(){MyMar =setInterval(Marquee,speed)} //鼠标移开时重设定时器--></script><DIV id=demo_1 style="OVERFLOW: hidden; HEIGHT: 136px"><DIV id=demo1_1><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div><div id=gleft><a href=""><img src="" border="0" width=150 height="120"/></a></div></DIV><DIV id=demo2_1></DIV></DIV><SCRIPT>var speed=25demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetWidth-demo.scrollLeft<=0)demo.scrollLeft-=demo1.offsetWidthelse{demo.scrollLeft++}}var MyMar=setInterval(Marquee,speed)demo.onmouseover=function() {clearInterval(MyMar)} demo.onmouseout=function(){MyMar=setInterval(Marquee,speed)} </SCRIPT> 其中<div id=gleft>这里的gleft的样式你自己定义下就OK 了。