JS 实现产品图片的轮播,支持向左向右滚动
2014-12-25 10:43
489 查看
最近给同学做个企业网站,需要将产品图片滚动,下面是实现的代码:
这是html的,主要是左右两个箭头图标,以及中间的图片:
下面是相应实现的Js:
这是html的,主要是左右两个箭头图标,以及中间的图片:
<div style="width:20px;height:130px;float:left;background:url(images/youjiantou.jpg);margin-left:10px;margin-right:10px;" onclick="GotoLeft()"></div> <div id="demox" style="width:880px;overflow:hidden;position: relative;float:left"> <div id="demo11" style="position: relative;"> <div style="margin-top:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡1</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡2</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #FF3333;"/><div style="width:130px;height:20px;text-align:center">氯化蜡3</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡4</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡5</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡6</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡7</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡8</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡9</div></div> <div style="margin-left:20px;margin-top:15px;float:left;width:130px;height:130px;cursor:pointer"><img alt="" src="images/天空1.jpg" style="width:130px;height:110px;border:2px solid #aaaaaa;"/><div style="width:130px;height:20px;text-align:center">氯化蜡10</div></div> </div> </div> 17 <div style="width:20px;height:130px;float:left;background:url(images/zuojiantou.jpg);margin-left:10px;" onclick="GotoRight()"></div>
下面是相应实现的Js:
//点击向左的箭头,图片往左翻滚 function GotoLeft() { clearInterval(MyMar); MyMar = setInterval(Marquee_left, speed); demox.onmouseover = function () { clearInterval(MyMar) }; demox.onmouseout = function () { MyMar = setInterval(Marquee_left, speed) }; } //图片向右翻转 function GotoRight() { clearInterval(MyMar); MyMar = setInterval(Marquee_right, speed); demox.onmouseover = function () { clearInterval(MyMar) }; demox.onmouseout = function () { MyMar = setInterval(Marquee_right, speed) }; } //图片向右滚动滚动 function Marquee_right() { //alert(demox.scrollLeft + " " + demo11.offsetWidth); if (demox.scrollLeft <= 0) { demox.scrollLeft += demo11.offsetWidth; } else { demox.scrollLeft--; } } //图片向左滚动滚动 function Marquee_left() { demox.scrollLeft++; }
相关文章推荐
- js实现图片的无缝轮播滚动
- JS实现可左右滚动产品图片展示
- ViewPager:真正实现图片的无限轮播、自定义指示点和条目点击事件(支持长按暂停滚动)
- js实现淘宝首页图片轮播效果(修正图片滚动顺序的问题)
- js实现支持手机滑动切换的轮播图片效果实例
- 完美实现js焦点轮播效果(二)(图片可滚动)
- js实现支持手机滑动切换的轮播图片效果实例
- js实现图片向上连续滚动特效代码(含注释)
- JS实现图片无缝滚动
- jb51站长推荐的用js实现的多浏览器支持的图片轮换展示效果ie,firefox
- ASP.NET中利用JS实现图片滚动
- 【转】js实现图片滚动效果
- 用js实现的一个Flash滚动轮换显示图片代码生成器
- 使用JS实现图片无限循环左右滚动
- js实现图片等比缩略显示 支持IE/FF
- js实现图片等比缩略显示 支持IE/FF
- js实现图片的点击滚动效果
- 图片无间断滚动JS实现代码
- JS实现多张图片纵向横向无缝滚动
- 一个图片轮换显示的实现,使用DIV+JS,支持Firefox,IE,Safiri