常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全
JS轮播图(无缝连接的轮播图实现,含代码供参考)

JS轮播图(⽆缝连接的轮播图实现,含代码供参考)需求:实现轮播图,图⽚⽆缝切换,⾃动播放。
实现效果:思考⼀下:在图⽚列表后⾯多加⼀张图⽚,这张图⽚是第⼀张图⽚(为了确保⽆缝衔接)。
图⽚就是平铺放在⼀个pic⾥⾯的,每次移动就是改变的pic的left值。
来撸代码~~。
所有的代码放在最后⾯,这⾥只讲⼀些重要的⽅法:为防⽌懵逼:先贴出封装函数move()的代码供参考function move(ele, attr, speed, target, callback){//获取当前的位置//从左往右进⾏移动 --- current<target speed//从右往左进⾏移动 --- current>target -speedvar current = parseInt(getStyle(ele, attr));// 810 > 800if(current>target){speed = -speed;}//定时器累加问题 --- 先清除再开启clearInterval(ele.timer);ele.timer = setInterval(function(){//获取元素的现在位置var begin = parseInt(getStyle(ele, attr));//步长var step = begin + speed;//判断当step>800, 让step = 800//从左往右进⾏移动 --- speed>0 正值//从右往左进⾏移动 --- speed<0 负值// -10 0 10 超过800直接变成 800if(speed<0 && step<target || speed>0 && step>target){step = target;}//赋值元素ele.style[attr] = step + "px";//让元素到达⽬标值时停⽌ 800pxif(step == target){clearInterval(ele.timer);//当move函数执⾏完毕后, 就执⾏它了//当条件都满⾜时才执⾏callback回调函数callback && callback();}},30)//步长是30}第⼀步:我们先来实现那个圆形按钮的点击事件。
多张图片滚动代码大全

多张图片滚动代码大全图片滚动代码(从右向左滚动)<marquee scrollamount=1 scrolldelay=3 valign=middle behavior="scroll"><img border="0" src="要滚动的图片地址1"><img border="0" src="要滚动的图片地址2"></marquee>图片滚动代码(从下往上滚动)<marquee onMouseOver="this.stop()" onMouseOut="this.start()" align=center direction=up scrollamount=1 scrolldelay=3 valign=middle behavior="scroll"><img border="0" src="要滚动的图片地址1"><img border="0" src="要滚动的图片地址2"></marquee>改版:<marquee ONMOUSEOUT=this.scrollDelay=1 ONMOUSEOVER=this.scrollDelay=600 scrollamount=1SCROLLDELAY=1 border=0 direction=up scrolldelay=70 width=180 height=130 align=middle> <img border="0" src="要滚动的图片地址1"><img border="0" src="要滚动的图片地址2"></marquee>说明:1.direction属性:决定文本的滚动方向,分为向左left和向右right,up和down默认状态向左。
用JS实现图片轮播效果代码(一)

font-weight: bold;
opacity: .5;
font-size: 40px;
z-index: 3;
}
.carousel-control:hover{
color:fff;
text-decoration: none;
opacity: .9;
outline: none;
imgs[i].style.display = 'block';
lis[i].style.fontSize = '26px';
lis[i].style.color = '#fff';
}
//自动播放的事件处理
function autobofang(){
if(pic_index >= lis.length){
<div class="item "><img src="./img/lunbo1.jpg" alt="第一张图片"></div>
<div class="item"><img src="./img/lunbo2.jpg" alt="第二张图片"></div>
var imgs = lunbo.getElementsByTagName('img');
var uls = lunbo.getElementsByTagName('ul');
Javascript实现图片不间断滚动的代码

这篇文章主要分享一段js图片不间断滚动的代码,蛮优秀的,需要的朋友可以参考下。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"/><title>滚动测试</title><script type="text/javascript">/** * @para obj 目标对象如:demo,deml1,demo2 中的"demo" 可任意,只要不重复 * * @para speed 滚动速度越大越慢 * * @para direction 滚动方向包括:left,right,down,up * * @para objWidth 总可见区域宽度 * * @para objHeight 总可见区域高度 * * @para filePath 存放滚动图片的路径(如果是自动获取文件夹里的图片滚动) * * @para contentById 对某id为contentById下的内容进行滚动此滚动与filePath不能共存请注意 * * @para 用法实例scrollObject("res",50,"up",470,200,"","resource") 对contentById(resource)下内容进行滚动 * * @para 用法实例scrollObject("res",50,"up",470,200,"d:\\images\\","") 对filePath(images)下内容自动获取并进行滚动,目前只支持ie */ var $ =function(id){return document.getElementById(id)} // 滚动function scrollObject(obj,speed,direction,objWidth,objHeight,filePath,contentById) { // 执行初始化if(direction=="up"||direction=="down") document.write(UDStructure()); else document.write(LRStructure()); var demo = $(obj); var demo1 = $(obj+"1"); var demo2 = $(obj+"2"); var speed=speed; $(contentById).style.display="none" demo.style.overflow="hidden"; demo.style.width = objWidth+"px"; demo.style.height = objHeight+"px"; demo.style.margin ="0 auto"; if(filePath!="") demo1.innerHTML=file(); if(contentById!="") demo1.innerHTML=$(contentById).innerHTML; demo2.innerHTML=demo1.innerHTML; // 左右滚动function LRStructure() { var _html =""; _html+="<div id='"+obj+"' >"; _html+="<table border='0' align='left' cellpadding='0' cellspacing='0' cellspace='0'>"; _html+="<tr>"; _html+="<td nowrap='nowrap' id='"+obj+"1' >"; // 此处是放要滚动的内容 _html+="</td>"; _html+="<td nowrap='nowrap' id='"+obj+"2' ></td>"; _html+="</tr>"; _html+="</table>"; _html+="</div>"; return _html; } // 上下滚动的结构function UDStructure() { var _html =""; _html+="<div id="+obj+" >"; _html+="<table border='0' align='left' cellpadding='0' cellspacing='0' cellspace='0'>"; _html+="<tr>"; _html+="<td id='"+obj+"1' >"; // 此处是放要滚动的内容 _html+="</td>"; _html+="</tr>"; _html+="<tr>"; _html+="<td id='"+obj+"2' ></td>"; _html+="</tr>"; _html+="</table>"; _html+="</div>"; return _html; } // 取得文件夹下的图片function file() { var tbsource = filePath;//本地文件夹路径 filePath = filePath.toString(); if (filePath=="") return""; var imgList =""; var objFSO =new ActiveXObject('Scripting.FileSystemObject'); // 文件夹是否存在if(!objFSO.FolderExists(tbsource)) { alert("<"+tbsource+">该文件夹路径不存在,或者路径不能含文件名!"); objFSO =null; return; } var objFolder = objFSO.GetFolder(tbsource); var colFiles =new Enumerator(objFolder.Files); var re_inf1 =/\.jpg$/; //验证文件夹文件是否jpg文件 for (;!colFiles.atEnd();colFiles.moveNext()) //读取文件夹下文件 { var objFile = colFiles.item(); if(re_inf1.test(.toLowerCase())) { imgList +="<img src="+filePath+"/"++">"; } } return imgList; } // 向左滚function left() { if(demo2.offsetWidth-demo.scrollLeft<=0) { demo.scrollLeft-=demo1.offsetWidth; } else { demo.scrollLeft++; } } // 向右滚function right() { if(demo.scrollLeft<=0) { demo.scrollLeft+=demo2.offsetWidth; } else { demo.scrollLeft-- } } // 向下滚function down() { if(demo1.offsetTop-demo.scrollTop>=0) { demo.scrollTop+=demo2.offsetHeight; } else { demo.scrollTop-- } } // 向上滚function up() { if(demo2.offsetTop-demo.scrollTop<=0) { demo.scrollTop-=demo1.offsetHeight; } else { demo.scrollTop++ } } // 切换方向function swichDirection() { switch(direction) { case"left": return left(); break; case"right": return right(); break; case"up": return up(); break; default: return down(); } } // 重复执行var myMarquee=setInterval(swichDirection,speed); // 鼠标悬停 demo.onmouseover=function() {clearInterval(myMarquee);} // 重新开始滚动 demo.onmouseout=function() { myMarquee=setInterval(swichDirection,speed);} }</script></head><body><div id="img"> <table width="1000" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="200"><img src="/attachment/200910/22/4188617_12561994098532.jpg" alt="" width="200" height="150"/></td> <td width="200"><img src="/2008-05-27/2008527145211519_2.jpg" alt="" width="200" height="150"/></td> <td width="200"><img src="/20090823/383152_215728074589_2.jpg" alt="" width="200" height="150"/></td> <td width="200"><img src="/20100628/4643449_170245009531_2.jpg" alt="" width="200" height="150"/></td> <td width="200"><img src="/2008-05-30/20085309524648_2.jpg" alt="" width="200" height="150"/></td> </tr> </table></div><script type="text/javascript">scrollObject("sr",50,"right",800,160,"","img")</script></body></html>以上就是本文的全部内容。
javascript实现图片左右滚动效果【可自动滚动,有左右按钮】

javascript实现图⽚左右滚动效果【可⾃动滚动,有左右按钮】本⽂实例讲述了javascript实现图⽚左右滚动效果。
分享给⼤家供⼤家参考,具体如下:html代码:<!doctype html><html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/><meta name="renderer" content="webkit"/><meta name="keywords" content=""/><meta name="description" content=""/><title>图⽚滚动</title><style>*{margin:0;padding:0;}ul{list-style:none;}img{border:0;}.scroll{width:358px;height:63px;}.scroll_left{width:23px;height:63px;background:url(images/btn_left.jpg) no-repeat;float:left;}.scroll_right{width:23px;height:63px;background:url(images/btn_right.jpg) left no-repeat;float:left;}.pic{width:312px;height:73px;float:left;}.pic ul{display:block;}.pic li{float:left;display:inline;width:104px;text-align:center;}</style></head><body><div style="margin:100px auto;width:358px;"><div class="scroll"><div class="scroll_left" id="LeftArr"></div><div class="pic" id="scrollPic"><ul><li><a href="#" target="_blank" title=""><img src="images/pic01.png" width="100" height="63" alt="" /></a></li><li><a href="#" target="_blank" title=""><img src="images/pic02.jpg" width="100" height="63" alt="" /></a></li><li><a href="#" target="_blank" title=""><img src="images/pic03.jpg" width="100" height="63" alt="" /></a></li><li><a href="#" target="_blank" title=""><img src="images/pic04.jpg" width="100" height="63" alt="" /></a></li><li><a href="#" target="_blank" title=""><img src="images/pic05.jpg" width="100" height="63" alt="" /></a></li><li><a href="#" target="_blank" title=""><img src="images/pic06.jpg" width="100" height="63" alt="" /></a></li></ul></div><div class="scroll_right" id="RightArr"></div></div></div></body></html><script src="scrollPic.js"></script><script>window.onload = function(){scrollPic();}function scrollPic() {var scrollPic = new ScrollPic();scrollPic.scrollContId = "scrollPic"; //内容容器IDscrollPic.arrLeftId = "LeftArr";//左箭头IDscrollPic.arrRightId = "RightArr"; //右箭头IDscrollPic.frameWidth = 312;//显⽰框宽度scrollPic.pageWidth = 104; //翻页宽度scrollPic.speed = 10; //移动速度(单位毫秒,越⼩越快)scrollPic.space = 10; //每次移动像素(单位px,越⼤越快)scrollPic.autoPlay = true; //⾃动播放scrollPic.autoPlayTime = 3; //⾃动播放间隔时间(秒)scrollPic.initialize(); //初始化}</script>scrollPic.js 代码:var sina = {return eval('document.getElementById("' + objName + '")')} else {return eval('document.all.' + objName)}},isIE : navigator.appVersion.indexOf("MSIE") != -1 ? true : false,addEvent : function (l, i, I) {if (l.attachEvent) {l.attachEvent("on" + i, I)} else {l.addEventListener(i, I, false)}},delEvent : function (l, i, I) {if (l.detachEvent) {l.detachEvent("on" + i, I)} else {l.removeEventListener(i, I, false)}},readCookie : function (O) {var o = "",l = O + "=";if (document.cookie.length > 0) {var i = document.cookie.indexOf(l);if (i != -1) {i += l.length;var I = document.cookie.indexOf(";", i);if (I == -1)I = document.cookie.length;o = unescape(document.cookie.substring(i, I))}};return o},writeCookie : function (i, l, o, c) {var O = "",I = "";if (o != null) {O = new Date((new Date).getTime() + o * 3600000);O = "; expires=" + O.toGMTString()};if (c != null) {I = ";domain=" + c};document.cookie = i + "=" + escape(l) + O + I},readStyle : function (I, l) {if (I.style[l]) {return I.style[l]} else if (I.currentStyle) {return I.currentStyle[l]} else if (document.defaultView && document.defaultView.getComputedStyle) { var i = document.defaultView.getComputedStyle(I, null);return i.getPropertyValue(l)} else {return null}}};//滚动图⽚构造函数//UI&UE Dept. mengjia//080623function ScrollPic(scrollContId, arrLeftId, arrRightId, dotListId) {this.scrollContId = scrollContId;this.arrLeftId = arrLeftId;this.arrRightId = arrRightId;this.dotListId = dotListId;this.dotClassName = "dotItem";this.dotOnClassName = "dotItemOn";this.dotObjArr = [];this.pageWidth = 0;this.frameWidth = 0;this.speed = 10;this.space = 10;this.autoPlay = true;this.autoPlayTime = 5;var _autoTimeObj,_scrollTimeObj,_state = "ready";this.stripDiv = document.createElement("DIV");this.listDiv01 = document.createElement("DIV");this.listDiv02 = document.createElement("DIV");if (!ScrollPic.childs) {ScrollPic.childs = []};this.ID = ScrollPic.childs.length;ScrollPic.childs.push(this);this.initialize = function () {if (!this.scrollContId) {throw new Error("必须指定scrollContId.");return};this.scrollContDiv = sina.$(this.scrollContId);if (!this.scrollContDiv) {throw new Error("scrollContId不是正确的对象.(scrollContId = \"" + this.scrollContId + "\")");return};this.scrollContDiv.style.width = this.frameWidth + "px";this.scrollContDiv.style.overflow = "hidden";this.listDiv01.innerHTML = this.listDiv02.innerHTML = this.scrollContDiv.innerHTML;this.scrollContDiv.innerHTML = "";this.scrollContDiv.appendChild(this.stripDiv);this.stripDiv.appendChild(this.listDiv01);this.stripDiv.appendChild(this.listDiv02);this.stripDiv.style.overflow = "hidden";this.stripDiv.style.zoom = "1";this.stripDiv.style.width = "32766px";if(-[1,]){this.listDiv01.style.cssFloat = "left";this.listDiv02.style.cssFloat = "left";}else{this.listDiv01.style.styleFloat = "left";this.listDiv02.style.styleFloat = "left";}sina.addEvent(this.scrollContDiv, "mouseover", Function("ScrollPic.childs[" + this.ID + "].stop()"));sina.addEvent(this.scrollContDiv, "mouseout", Function("ScrollPic.childs[" + this.ID + "].play()"));if (this.arrLeftId) {this.arrLeftObj = sina.$(this.arrLeftId);if (this.arrLeftObj) {sina.addEvent(this.arrLeftObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].rightMouseDown()")); sina.addEvent(this.arrLeftObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"));sina.addEvent(this.arrLeftObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].rightEnd()"))}};if (this.arrRightId) {this.arrRightObj = sina.$(this.arrRightId);if (this.arrRightObj) {sina.addEvent(this.arrRightObj, "mousedown", Function("ScrollPic.childs[" + this.ID + "].leftMouseDown()")); sina.addEvent(this.arrRightObj, "mouseup", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"));sina.addEvent(this.arrRightObj, "mouseout", Function("ScrollPic.childs[" + this.ID + "].leftEnd()"))}};if (this.dotListId) {this.dotListObj = sina.$(this.dotListId);if (this.dotListObj) {var pages = Math.round(this.listDiv01.offsetWidth / this.frameWidth + 0.4),i,tempObj;for (i = 0; i < pages; i++) {tempObj = document.createElement("span");this.dotListObj.appendChild(tempObj);this.dotObjArr.push(tempObj);if (i == this.pageIndex) {tempObj.className = this.dotClassName} else {tempObj.className = this.dotOnClassName};tempObj.title = "第" + (i + 1) + "页";sina.addEvent(tempObj, "click", Function("ScrollPic.childs[" + this.ID + "].pageTo(" + i + ")"))}};if (this.autoPlay) {this.play()}};this.leftMouseDown = function () {if (_state != "ready") {return};_state = "floating";_scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveLeft()", this.speed)};this.rightMouseDown = function () {if (_state != "ready") {return};_state = "floating";_scrollTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].moveRight()", this.speed)};this.moveLeft = function () {if (this.scrollContDiv.scrollLeft + this.space >= this.listDiv01.scrollWidth) {this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + this.space - this.listDiv01.scrollWidth } else {this.scrollContDiv.scrollLeft += this.space};this.accountPageIndex()};this.moveRight = function () {if (this.scrollContDiv.scrollLeft - this.space <= 0) {this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - this.space } else {this.scrollContDiv.scrollLeft -= this.space};this.accountPageIndex()};this.leftEnd = function () {if (_state != "floating") {return};_state = "stoping";clearInterval(_scrollTimeObj);var fill = this.pageWidth - this.scrollContDiv.scrollLeft % this.pageWidth;this.move(fill)};this.rightEnd = function () {if (_state != "floating") {return};_state = "stoping";clearInterval(_scrollTimeObj);var fill = -this.scrollContDiv.scrollLeft % this.pageWidth;this.move(fill)};this.move = function (num, quick) {var thisMove = num / 5;if (!quick) {if (thisMove > this.space) {thisMove = this.space};if (thisMove < -this.space) {thisMove = -this.space}};if (Math.abs(thisMove) < 1 && thisMove != 0) {thisMove = thisMove >= 0 ? 1 : -1} else {thisMove = Math.round(thisMove)};var temp = this.scrollContDiv.scrollLeft + thisMove;if (thisMove > 0) {if (this.scrollContDiv.scrollLeft + thisMove >= this.listDiv01.scrollWidth) {this.scrollContDiv.scrollLeft = this.scrollContDiv.scrollLeft + thisMove - this.listDiv01.scrollWidth } else {this.scrollContDiv.scrollLeft += thisMove} else {if (this.scrollContDiv.scrollLeft - thisMove <= 0) {this.scrollContDiv.scrollLeft = this.listDiv01.scrollWidth + this.scrollContDiv.scrollLeft - thisMove} else {this.scrollContDiv.scrollLeft += thisMove}};num -= thisMove;if (Math.abs(num) == 0) {_state = "ready";if (this.autoPlay) {this.play()};this.accountPageIndex();return} else {this.accountPageIndex();setTimeout("ScrollPic.childs[" + this.ID + "].move(" + num + "," + quick + ")", this.speed)}};this.next = function () {if (_state != "ready") {return};_state = "stoping";this.move(this.pageWidth, true)};this.play = function () {if (!this.autoPlay) {return};clearInterval(_autoTimeObj);_autoTimeObj = setInterval("ScrollPic.childs[" + this.ID + "].next()", this.autoPlayTime * 1000)};this.stop = function () {clearInterval(_autoTimeObj)};this.pageTo = function (num) {if (_state != "ready") {return};_state = "stoping";var fill = num * this.frameWidth - this.scrollContDiv.scrollLeft;this.move(fill, true)};this.accountPageIndex = function () {this.pageIndex = Math.round(this.scrollContDiv.scrollLeft / this.frameWidth);if (this.pageIndex > Math.round(this.listDiv01.offsetWidth / this.frameWidth + 0.4) - 1) {this.pageIndex = 0};var i;for (i = 0; i < this.dotObjArr.length; i++) {if (i == this.pageIndex) {this.dotObjArr[i].className = this.dotClassName} else {this.dotObjArr[i].className = this.dotOnClassName}}}};参数说明:var scrollPic = new ScrollPic(); //定义变量,并初始化⽅法 scrollContId //滚动容器的ID arrLeftId //左按钮ID arrRightId //右按钮ID frameWidth //显⽰框宽度 pageWidth //翻页宽度 speed //移动速度(单位毫秒,越⼩越快) space //每次移动像素(单位px,越⼤越快) autoPlay //⾃动播放 autoPlayTime //⾃动播放间隔时间(秒) initialize() //初始化完整实例代码点击此处。
Js无缝滚动图片和文字(上下,左右)

Js无缝滚动图片和文字(上下,左右)从下到上:<div id=demo style="overflow:hidden; width:128px; height:300px;"><div id=demo1><ul><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li><li>图片连续循环滚动代码(向上)</li></ul></div><div id=demo2></div></div><script language="javascript">var speed=30demo2.innerHTML=demo1.innerHTMLfunction Marquee(){if(demo2.offsetTop-demo.scrollTop<=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: 605px; height:100px;margin-left:7px"><table height=100 cellspacing=1 class="roll_img"><tbody><tr><td id=demo1 valign=top><img hspace=1 src="images/24999336.gif" border=0 width="100" height="80" /><img hspace=1 src="images/3b0e743b-3fbe-47c0-88d3-4f43be483c72.gif" border=0 width="100" height="80" /><img hspace=1 src="images/fdeb0f2e26a53dc08a139985.gif" border=0 width="100" height="80" /><img hspace=1 src="images/dnwx1.gif" border=0 width="100" height="80" /><img hspace=1 src="images/1225950981_g.gif" border=0 width="100" height="80" /><img hspace=1 src="images/1261703426-9896.gif" border=0 width="100" height="80" /><img hspace=1 src="images/cty8kdhtlq_w.gif" border=0 width="100" height="80" /></td><td id=demo2 valign=top><img hspace=1 src="images/24999336.gif" border=0 width="100" height="80" /><img hspace=1 src="images/3b0e743b-3fbe-47c0-88d3-4f43be483c72.gif" border=0 width="100" height="80" /><img hspace=1 src="images/fdeb0f2e26a53dc08a139985.gif" border=0 width="100" height="80" /><img hspace=1 src="images/dnwx1.gif" border=0 width="100" height="80" /><img hspace=1 src="images/1225950981_g.gif" border=0 width="100" height="80" /><img hspace=1 src="images/1261703426-9896.gif" border=0 width="100" height="80" /><img hspace=1 src="images/cty8kdhtlq_w.gif" border=0 width="100" height="80" /></td></tr></tbody></table><script type="text/javascript">var speed=30demo2.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>。
JavaScript经典效果集锦(滚动的图片)

<script language="javascript">imgArr=new Array()imgArr[0]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true'onMouseout='javascript:outHover=false;mvStart()'><imgsrc=/mapcard/images/LP_card_1.gif border=0></a>"imgArr[1]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true'onMouseout='javascript:outHover=false;mvStart()'><imgsrc=/mapcard/images/LP_card_1.gif border=0></a>"imgArr[2]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true'onMouseout='javascript:outHover=false;mvStart()'><imgsrc=/mapcard/images/LP_card_1.gif border=0></a>"imgArr[3]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true'onMouseout='javascript:outHover=false;mvStart()'><imgsrc=/mapcard/images/LP_card_1.gif border=0></a>"imgArr[4]="<a href=# onmouseMove='javascript:outHover=true' onMouseover='javascript:outHover=true'onMouseout='javascript:outHover=false;mvStart()'><imgsrc=/mapcard/images/LP_card_1.gif border=0></a>"var moveStep=4 //步长,单位:pixelvar moveRelax=100 //移动时间间隔,单位:msns4=(yers)?true:falsevar displayImgAmount=4 //视区窗口可显示个数var divWidth=220 //每块图片占位宽var divHeight=145 //每块图片占位高var startDnum=0var nextDnum=startDnum+displayImgAmountvar timeIDvar outHover=falsevar startDivClipLeftvar nextDivClipRightfunction initDivPlace(){if (ns4){for (i=0;i<displayImgAmount;i++){eval("document.divOuter.document.divAds"+i+".left="+divWidth*i)}for (i=displayImgAmount;i<imgArr.length;i++){eval("document.divOuter.document.divAds"+i+".left="+divWidth*displayImgAmount) }}else{for (i=0;i<displayImgAmount;i++){eval("document.all.divAds"+i+".style.left="+divWidth*i)}for (i=displayImgAmount;i<imgArr.length;i++){eval("document.all.divAds"+i+".style.left="+divWidth*displayImgAmount) }}}function mvStart(){timeID=setTimeout(moveLeftDiv,moveRelax)}function mvStop(){clearTimeout(timeID)}function moveLeftDiv(){if (ns4){for (i=0;i<=displayImgAmount;i++){eval("document.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left=doc ument.divOuter.document.divAds"+parseInt((startDnum+i)%imgArr.length)+".left-moveStep") }startDivClipLeft=parseInt(eval("document.divOuter.document.divAds"+startDnum+".clip.left"))nextDivClipRight=parseInt(eval("document.divOuter.document.divAds"+nextDnum+".clip.right") )if (startDivClipLeft+moveStep>divWidth){eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+divWidth) eval("document.divOuter.document.divAds"+startDnum+".left="+divWidth*displayImgAmount) eval("document.divOuter.document.divAds"+parseInt((nextDnum+1)%imgArr.length)+".left=document.divOuter.document.divAds"+nextDnum+".left+"+divWidth)eval("document.divOuter.document.divAds"+parseInt((nextDnum+1)%imgArr.length)+".clip.left =0")startDnum=(++startDnum)%imgArr.lengthnextDnum=(startDnum+displayImgAmount)%imgArr.lengthstartDivClipLeft=moveStep-(divWidth-startDivClipLeft)nextDivClipRight=moveStep-(divWidth-nextDivClipRight)}else{eval("document.divOuter.document.divAds"+nextDnum+".clip.left=0")startDivClipLeft+=moveStepnextDivClipRight+=moveStep}eval("document.divOuter.document.divAds"+startDnum+".clip.left="+startDivClipLeft)eval("document.divOuter.document.divAds"+nextDnum+".clip.right="+nextDivClipRight) }else{for (i=0;i<=displayImgAmount;i++){eval("document.all.divAds"+parseInt((startDnum+i)%imgArr.length)+".style.left=document.all.di vAds"+parseInt((startDnum+i)%imgArr.length)+".style.pixelLeft-moveStep")}startDivClipLeft=parseInt(eval("document.all.divAds"+startDnum+".currentStyle.clipLeft")) nextDivClipRight=parseInt(eval("document.all.divAds"+nextDnum+".currentStyle.clipRight")) if (startDivClipLeft+moveStep>divWidth){eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+divWidth+","+divHeight+",0"+")'") eval("document.all.divAds"+startDnum+".style.left="+divWidth*displayImgAmount)eval("document.all.divAds"+parseInt((nextDnum+1)%imgArr.length)+".style.left=document.all.di vAds"+nextDnum+".style.pixelLeft+"+divWidth)startDnum=(++startDnum)%imgArr.lengthnextDnum=(startDnum+displayImgAmount)%imgArr.lengthstartDivClipLeft=moveStep-(divWidth-startDivClipLeft)nextDivClipRight=moveStep-(divWidth-nextDivClipRight)}else{startDivClipLeft+=moveStepnextDivClipRight+=moveStep}eval("document.all.divAds"+startDnum+".style.clip='rect(0,"+divWidth+","+divHeight+","+start DivClipLeft+")'")eval("document.all.divAds"+nextDnum+".style.clip='rect(0,"+nextDivClipRight+","+divHeight+" ,0)'")}if (outHover){mvStop()}else{mvStart()}}function writeDivs(){if (ns4){document.write("<ilayer name=divOuter width=750 height="+divHeight+">")for (i=0;i<imgArr.length;i++){document.write("<layer name=divAds"+i+">")document.write(imgArr[i]+" ")document.write("</layer>")}document.write("</ilayer>")document.close()for (i=displayImgAmount;i<imgArr.length;i++){eval("document.divOuter.document.divAds"+i+".clip.right=0")}}else{document.write("<div id=divOuter style='position:relative' width=750 height="+divHeight+">")for (i=0;i<imgArr.length;i++){document.write("<div id=divAds"+i+" style='position:absolute;clip:rect(0,"+divWidth+","+divHeight+",0)'>")document.write(imgArr[i]+" ")document.write("</div>")}document.write("</div>")for (i=displayImgAmount;i<imgArr.length;i++){eval("document.all.divAds"+i+".style.clip='rect(0,0,"+divHeight+",0)'") }}}</script><BODY onload=javascript:mvStart()><SCRIPT language=javascript>writeDivs();initDivPlace();</SCRIPT>。
js轮播图代码分享_

js轮播图代码分享_大家喜爱的js轮播图片效果,分享给大家。
一、要点:1.页面加载时,图片重合,叠在一起[肯定定位];2.第一张显示,其它隐蔽;3.设置下标,给下标设置颜色让它随图片移动;4.鼠标移动到图片上去,显示左右移动图标,鼠标移走,连续轮播;二、实现代码:html代码:!DOCTYPE htmlhtml xmlns="l"headmeta http-equiv="Content-Type" content="text/html; charset=utf-8"/title轮播图/titlelink href="css/LunBimg.css" rel="stylesheet" /script src="js/jquery-1.10.2.min.js"/scriptscript src="js/LunBimg.js"/script/headbodydiv id="allswapImg"div class="swapImg"img src="image/1.jpg" //div div class="swapImg"img src="image/2.jpg" //div div class="swapImg"img src="image/3.jpg" //div div class="swapImg"img src="image/4.jpg" //div div class="swapImg"img src="image/5.jpg" //div div class="swapImg"img src="image/6.jpg" //div /divdiv class="btn btnLeft"/divdiv class="btn btnRight"/divdiv id="tabs"div class="tab bg"1/divdiv class="tab"2/divdiv class="tab"3/divdiv class="tab"4/divdiv class="tab"5/divdiv class="tab"6/div/div/body/htmlcss代码:* {padding:0px;margin:0px;}.swapImg {position:absolute;}.btn {position:absolute;height:90px;width:60px;background:rgba(0,0,0,0.5);/*设置背景颜色为黑色,透亮度为50%*/color:#ffffff;text-align:center;line-height:90px;font-size:40px;top:155px;/*图片高度400/2-45*/cursor:pointer;/*display:none;*/}.btnRight {left:840px;/*图片宽度900-导航宽度60*/}#tabs {position:absolute; top:370px;margin-left:350px; }.tab {height:20px;width:20px;background:#05e9e2; line-height:20px; text-align:center; font-size:10px;float:left;color:#ffffff;margin-right:10px; border-radius:100%; cursor:pointer;}.bg {background:#00ff21; }js代码:/// reference path="_references.js" /var i = 0;//全局变量//定义一个变量用来猎取轮播的过程var time;$(function (){//1.页面加载后,找到Class等于swapImg的第一个对象,让它显示,它的兄弟元素隐蔽$(".swapImg").eq(0).show().siblings().hide();showTime();//当鼠标放到下标上显示该图片,鼠标移走连续轮播$(".tab").hover(function (){//猎取到当前鼠标所在的下标的索引i = $(this).index();show();//鼠标放上去之后,怎么停止呢?猎取到变量的过程,清除轮播,把变量传进去clearInterval(time);}, function (){showTime();});//要求四,当我点击左右切换$(".btnLeft").click(function (){//1.点击之前要停止轮播clearInterval(time);//点了之后,-1if (i == 0){i =6;}i--;show();showTime();});$(".btnRight").click(function () { //1.点击之前要停止轮播clearInterval(time);//点了之后,-1if (i == 5) {i = -1;}i++;show();showTime();});});function show() {//$("#allswapImg").hover(function ()//{// $(".btn").show();//}, function ()//{// $(".btn").hide();//});//fadeIn(300)淡入,fadeout(300)淡出,过滤时间0.3s$(".swapImg").eq(i).fadeIn(300).siblings().fadeOut( );$(".tab").eq(i).addClass("bg").siblings().removeClass("bg");}function showTime(){time = setInterval(function () {i++;if (i == 6) {//只有6张图片,所以i不能超过6,假如i等于6时,我们就让它等于第一张i = 0;}show();}, 3000);}以上就是本文的全部内容,盼望对大家的学习有所关心...。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<script>
var speed=30;
var colee2=document.getElementById("colee2");
var colee1=document.getElementById("colee1");
var colee=document.getElementById("colee");
var colee_bottom2=document.getElementById("colee_bottom2");
var colee_bottom1=document.getElementById("colee_bottom1");
var colee_bottom=document.getElementById("colee_bottom");
var speed=30//速度数值越大速度越慢
var colee_left2=document.getElementById("colee_left2");
var colee_left1=document.getElementById("colee_left1");
var colee_left=document.getElementById("colee_left");
<tr><td id="colee_right1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
colee_bottom2.innerHTML=colee_bottom1.innerHTML
colee_bottom.scrollTop=colee_bottom.scrollHeight
function Marquee2(){
if(colee_bottom1.offsetTop-colee_bottom.scrollTop>=0)
}else{
colee.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
colee.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="colee_left1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
colee_bottom.scrollTop+=colee_bottom2.offsetHeight
else{
colee_bottom.scrollTop--
}
}
var MyMar2=setInterval(Marquee2,speed)
colee_bottom.onmouseover=function() {clearInterval(MyMar2)}
colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script>
<!--向上滚动代码结束-->
<br>
<!--下面是向下滚动代码-->
<div id="colee_bottom" style="overflow:hidden;height:253px;width:410px;">
</script>
<!--向左滚动代码结束-->
<br>
<!--下面是向右滚动代码-->
<div id="colee_right" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<div id="colee_bottom1">
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
else{
colee_left.scrollLeft++
}
}
var MyMar3=setInterval(Marquee3,speed)
colee_left.onmouseover=function() {clearInterval(MyMar3)}
colee_left.onmouseout=function() {MyMar3=setInterval(Marquee3,speed)}
<tr align="center">
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
<td><p><img src="/jscss/demoimg/200907/bg3.jpg"></p></td>
colee_bottom.onmouseout=function() {MyMar2=setInterval(Marquee2,speed)}
</script>
<!--向下滚动代码结束---下面是向左滚动代码-->
<div id="colee_left" style="overflow:hidden;width:500px;">
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
<p><img src="/jscss/demoimg/200907/bg3.jpg"></p>
</div>
<div id="colee_bottom2"></div>
</div>
<script>
var speed=30
var colee_right2=document.getElementById("colee_right2");
var colee_right1=document.getElementById("colee_right1");