图片不间断左右滚动效果,并且可以控制方向
页面载入时默认滚动,左右方向可以通过按钮点击控制,不要贴alixixi的那个代码,可以拖动的那个,在页面里太卡,而且会把页面挤变形。谢谢了!...
页面载入时默认滚动,左右方向可以通过按钮点击控制,不要贴alixixi的那个代码,可以拖动的那个,在页面里太卡,而且会把页面挤变形。
谢谢了! 展开
谢谢了! 展开
1个回答
展开全部
<div id="demo" style="overflow:hidden;width:510px; border:1px solid blue;">
<div id="demo1">
<table cellspacing="0">
<tr>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
</tr>
</table>
</div>
<div id="demo2"></div>
</div>
<input type="button" value="向左" onclick="changeRedirect(0)">
<input type="button" value="向右" onclick="changeRedirect(1)">
<script style="text/javascript">
var speed=40;//数值越大,速度越慢
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
var demo=document.getElementById("demo");
demo.scrollLeft=demo.scrollWidth
function MarqueeLeft(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
function MarqueeRight(){
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else{
demo.scrollLeft--
}
}
var MyMar=setInterval(MarqueeRight,speed);
demo.onmouseover=function() {clearInterval(MyMar);}
demo.onmouseout=function() {MyMar=setInterval(MarqueeRight,speed);}
function changeRedirect(i)
{
clearInterval(MyMar);
if(i==0)
{
MyMar=setInterval(MarqueeLeft,speed);
demo.onmouseout=function() {MyMar=setInterval(MarqueeLeft,speed);}
}
else
{
MyMar=setInterval(MarqueeRight,speed);
demo.onmouseout=function() {MyMar=setInterval(MarqueeRight,speed);}
}
}
</script>
<div id="demo1">
<table cellspacing="0">
<tr>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
<td><img src="http://www.baidu.com/img/lm.gif"></td>
<td><img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif"></td>
</tr>
</table>
</div>
<div id="demo2"></div>
</div>
<input type="button" value="向左" onclick="changeRedirect(0)">
<input type="button" value="向右" onclick="changeRedirect(1)">
<script style="text/javascript">
var speed=40;//数值越大,速度越慢
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
var demo=document.getElementById("demo");
demo.scrollLeft=demo.scrollWidth
function MarqueeLeft(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++
}
}
function MarqueeRight(){
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else{
demo.scrollLeft--
}
}
var MyMar=setInterval(MarqueeRight,speed);
demo.onmouseover=function() {clearInterval(MyMar);}
demo.onmouseout=function() {MyMar=setInterval(MarqueeRight,speed);}
function changeRedirect(i)
{
clearInterval(MyMar);
if(i==0)
{
MyMar=setInterval(MarqueeLeft,speed);
demo.onmouseout=function() {MyMar=setInterval(MarqueeLeft,speed);}
}
else
{
MyMar=setInterval(MarqueeRight,speed);
demo.onmouseout=function() {MyMar=setInterval(MarqueeRight,speed);}
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询