web前端|js教程
仿搜狐,FLASH图片切换效果
web前端-js教程
前2个星期看到一位朋友说如何用JS实现/这个页中FLASH图片切换效果,这两天有空,做了一个,大家评评:
【加载图片慢点请等会】
贵金属直播室源码下载,ubuntu编译代码命令,爬虫采集分析存储,wopi php,广东seo技巧lzw
源码之家文章列表,怎么覆盖安装ubuntu,tomcat启动时内存不足,爬虫好接单吗,php输出斐波那契数列优化,seo搜索排序lzw
* { margin:0; padding:0; } body {margin:0;color:#88c; background:#333; } img { margin:0; padding:0; border:0; } #js_F {position:relative;top:10px; left:10px;overflow:hidden;width:395px; height:185px;background:#33c; } .div_img {position:absolute; top:0;width:295px; height:185px;cursor:pointer; } #div_img_0 { z-index:5; left:0; } #div_img_1 { z-index:4; left:25px; } #div_img_2 { z-index:3; left:50px; } #div_img_3 { z-index:2; left:75px; } #div_img_4 { z-index:1; left:100px; }
图库asp源码,vscode运行网页项目,ubuntu无法重装,tomcat 需要密码,嵌入式 移植SQLite,浴室洗手盆有小爬虫,php判断平板,新兴seo推广公司,淘宝客交流网站,打包网页小程序,新闻稿审核模板lzw
<!–*/ var div_imgs = document.getElementById("js_F").getElementsByTagName("div"); var imgLeft = [0, 25, 50, 75, 100]; //5个图片的初始left值 var imgWidth = 270; //图片的宽度 var atf = [true, true, true, true, true]; //5个图片的位置:true为右边,false为左边 var speed1 = 10, speed2 = 2000, mo = 15; //速度 var sTo; function jsf_move(n){clearTimeout(sTo);var thisL; //图片left值if (atf[n]) { //要移动的图片在右边 //需移动的图片(包括该图片左边的所有图片)向左边移动) for (var i=0; i<=n; i++) { //当前值-(图片宽度-(当前值-初始值))/速度 thisL = parseInt(getStyle(div_imgs[i],"left")); div_imgs[i].style.left = thisL – Math.ceil((imgWidth-(imgLeft[i]-thisL))/mo) + "px"; if (i=n; i–) { //当前值+(当前值-初始值)/速度 thisL = parseInt(getStyle(div_imgs[i],”left”)); div_imgs[i].style.left = thisL + Math.ceil(Math.abs(thisL-imgLeft[i])/mo) + “px”; if (i>n) atf[i] = true; //更改图片的位置状态 }}thisL = parseInt(getStyle(div_imgs[n],”left”));if ((atf[n] && thisL>(imgLeft[n]-imgWidth)) || (!atf[n] && thisL=3 && atf[n]) { atf[n] = false; sTo = setTimeout(function(){jsf_move(n);}, speed2); } else if (n==0 && !atf[n]) { atf[n] = true; sTo = setTimeout(function(){jsf_move(n);}, speed2); } else if (atf[n]){ atf[n] = false; sTo = setTimeout(function(){jsf_move(++n);}, speed2); } else { sTo = setTimeout(function(){jsf_move(–n);}, speed2); }} } //判断图片的位置 function jsf_mmove(n){clearTimeout(sTo);switch (n){case 0 : atf[0] = false; jsf_move(0); break;case 1 :case 2 :case 3 : if (atf[n-1]) { sTo = setTimeout(function(){jsf_move(n-1);}, speed1); } else if (atf[n]) { atf[n-1] = true; sTo = setTimeout(function(){jsf_move(n-1);}, speed1); } else { sTo = setTimeout(function(){jsf_move(n);}, speed1); } break;case 4 : atf = [false, false, false, true, true]; jsf_move(3); break; } } window.onload = function(){sTo = setTimeout(“jsf_move(0)”,speed2); } function getStyle( elem, name ) {if (elem.style[name]) { return elem.style[name]; }else if (elem.currentStyle) { return elem.currentStyle[name]; }else if (document.defaultView && document.defaultView.getComputedStyle) { name = name.replace(/([A-Z])/g,”-$1″); name = name.toLowerCase(); var s = document.defaultView.getComputedStyle(elem,””); return s && s.getPropertyValue(name);}else { return null; } } /*]]>*///–>
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]这个是有一点问题的,就是鼠标在移动的图片上滑过时,图片会停顿一下,解决方法是增加一个图片位置标记:-1为左边;0为移动中;1为右边,也可以增加一个移动方向的参数,具体就懒得写了。
下面再给一个自己写的图片切换效果:
<!–*/ var js_F = document.getElementById("js_F"); var imgList = ["/upload/0130202743347.jpg", "/upload/0130202744477.jpg", "/upload/0130202744721.jpg", "/upload/0130202744468.jpg", "/upload/0130202744674.jpg", ]; var imgTemp = new Array(); for (i=0; i<imgList.length; i++){imgTemp[i] = new Image();imgTemp[i].src = imgList[i]; } var imgs = new Array(); var imgID = 0, nextImgID, proveImgID; var tf = true; //图片移动方向标志 var speed1 = 10; speed2 = 3000; //速度 function imgInit(){var content = \;for (i=0; i<imgList.length; i++){ content += \ ’;}js_F.innerHTML = content;imgs = js_F.getElementsByTagName(‘img’);imgs[0].style.zIndex = 20;imgs[1].style.zIndex = 15; } function imgChange(){if ((imgID+1)<imgList.length){ nextImgID = imgID + 1;} else if (imgID-180){ imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)-10) + ‘px’; imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)+5) + ‘px’; setTimeout(‘imgShow()’,speed1); } else { tf = !tf; imgs[imgID].style.zIndex = 15; imgs[nextImgID].style.zIndex = 20; setTimeout(‘imgShow()’,speed1); }} else { if (parseInt(imgs[imgID].style.left)
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]