完美JQuery图片切换效果的简单实现

合集下载

jquery实现图片翻转特效

jquery实现图片翻转特效

效果图:CSS:html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,d el,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,tabl e,caption,tbody,tfoot,thead,tr,th,td { margin:0; padding:0; border:0; outline:0; font-weight:inherit; font-style:inherit; font-size:100%; font-family:inherit; vertical-align:baseline; }:focus { outline:0; }a:active { outline:none; }body { line-height:1; color:black; background:white; }ol,ul { list-style:none; }table { border-collapse:separate; border-spacing:0; }caption,th,td { text-align:left; font-weight:normal; }blockquote:before,blockquote:after,q:before,q:after { content:""; }blockquote,q { quotes:""""; }body {font:normal62.5%/1.5Helvetica,Arial,sans-serif;letter-spacing:0;color:#434343;background:#efefef url(../img/background.png)repeat top center;padding:20px0;position:relative;text-shadow:01px0rgba(255,255,255,.8);-webkit-font-smoothing: subpixel-antialiased;}#container {width:580px;padding:10px;margin:0auto;position:relative;z-index:0;}#example {width:600px;height:350px;position:relative;}#ribbon {position:absolute;top:-3px;left:-15px;z-index:500;}#frame {position:absolute;z-index:0;width:739px;height:341px;top:-3px;left:-80px;}#slides {position:absolute;top:15px;left:4px;z-index:100;}.slides_container {width:570px;overflow:hidden;position:relative;display:none;}.slides_container div.slide { width:570px;height:270px;display:block;}#slides.next,#slides.prev {position:absolute;top:107px;left:-39px;width:24px;height:43px;display:block;z-index:101;}#slides.next {left:585px;}.pagination {margin:26px auto0;width:100px;}.pagination li {float:left;margin:01px;list-style:none;}.pagination li a {display:block;width:12px;height:0;padding-top:12px;background-image:url(../img/pagination.png);background-position:00;float:left;overflow:hidden;}.pagination li.current a {background-position:0-12px;}.caption {z-index:500;position:absolute;bottom:-35px;left:0;height:30px;padding:5px20px020px;background:#000;background:rgba(0,0,0,.5);width:540px;font-size:1.3em;line-height:1.33;color:#fff;border-top:1px solid#000;text-shadow:none;}#footer {text-align:center;width:580px;margin-top:9px;padding:4.5px018px;border-top:1px solid#dfdfdf;}#footer p {margin:4.5px0;font-size:1.0em;}a:link,a:visited {color:#599100;text-decoration:none;}a:hover,a:active {color:#599100;text-decoration:underline;}.img_css{width:570px;height:270px;}JS:(function(a){a.fn.slides=function(b){return b=a.extend({},a.fn.slides.option,b),this.each(function(){function w(g,h,i){if(!p&&o){p=!0,b.animationStart(n+1);switch(g){case"next":l=n,k=n+1,k=e===k?0:k,r=f*2,g=-f*2,n=k; break;case"prev":l=n,k=n-1,k=k===-1?e-1:k,r=0,g=0,n=k;break;case"pagination":k=parseInt(i,10),l=a("."+b.pagin ationClass+" li."+b.currentClass+" a",c).attr("href").match("[^#/]+$"),k>l?(r=f*2,g=-f*2):(r=0,g=0),n=k}h==="fade"?b.crossfade?d.children(":eq("+k +")",c).css({zIndex:10}).fadeIn(b.fadeSpeed,b.fadeEasing,function(){b.autoHeight?d.animate({height:d.children(" :eq("+k+")",c).outerHeight()},b.autoHeightSpeed,function(){d.children(":eq("+l+")",c).css({display:"none",zIndex:0}),d.children(":eq("+k+")",c).css({zIndex:0}),b.animationComplete(k+1),p=!1}):(d.children(":eq("+l+")",c).css( {display:"none",zIndex:0}),d.children(":eq("+k+")",c).css({zIndex:0}),b.animationComplete(k+1),p=!1)}):d.childr en(":eq("+l+")",c).fadeOut(b.fadeSpeed,b.fadeEasing,function(){b.autoHeight?d.animate({height:d.children(":eq(" +k+")",c).outerHeight()},b.autoHeightSpeed,function(){d.children(":eq("+k+")",c).fadeIn(b.fadeSpeed,b.fadeEasin g)}):d.children(":eq("+k+")",c).fadeIn(b.fadeSpeed,b.fadeEasing,function(){a.browser.msie&&a(this).get(0).style. removeAttribute("filter")}),b.animationComplete(k+1),p=!1}):(d.children(":eq("+k+")").css({left:r,display:"block" }),b.autoHeight?d.animate({left:g,height:d.children(":eq("+k+")").outerHeight()},b.slideSpeed,b.slideEasing,functi on(){d.css({left:-f}),d.children(":eq("+k+")").css({left:f,zIndex:5}),d.children(":eq("+l+")").css({left:f,display:"no ne",zIndex:0}),b.animationComplete(k+1),p=!1}):d.animate({left:g},b.slideSpeed,b.slideEasing,function(){d.css({ left:-f}),d.children(":eq("+k+")").css({left:f,zIndex:5}),d.children(":eq("+l+")").css({left:f,display:"none",zIndex:0 }),b.animationComplete(k+1),p=!1})),b.pagination&&(a("."+b.paginationClass+"li."+b.currentClass,c).removeClass(b.currentClass),a("."+b.paginationClass+"li:eq("+k+")",c).addClass(b.currentClass))}}function x(){clearInterval(c.data("interval"))}function y(){b.pause?(clearTimeout(c.data("pause")),clearInterval(c.data("interval")),u=setTimeout(function(){clearTimeou t(c.data("pause")),v=setInterval(function(){w("next",i)},b.play),c.data("interval",v)},b.pause),c.data("pause",u)):x( )}a("."+b.container,a(this)).children().wrapAll('<div class="slides_control"/>');var c=a(this),d=a(".slides_control",c),e=d.children().size(),f=d.children().outerWidth(),g=d.children().outerHeight(),h= b.start-1,i=b.effect.indexOf(",")<0?b.effect:b.effect.replace("","").split(",")[0],j=b.effect.indexOf(",")<0?i:b.effect.replace("","").split(",")[1],k=0,l=0,m=0,n=0,o,p,q,r,s,t,u,v;if(e<2)returna("."+b.container,a(this)).fadeIn(b.fadeSpeed,b.fadeEasing,function(){o=!0,b.slidesLoaded()}),a("."+b.next+", ."+ b.prev).fadeOut(0),!1;if(e<2)return;h<0&&(h=0),h>e&&(h=e-1),b.start&&(n=h),b.randomize&&d.randomize(),a( "."+b.container,c).css({overflow:"hidden",position:"relative"}),d.children().css({position:"absolute",top:0,left:d.ch ildren().outerWidth(),zIndex:0,display:"none"}),d.css({position:"relative",width:f*3,height:g,left:-f}),a("."+b.conta iner,c).css({display:"block"}),b.autoHeight&&(d.children().css({height:"auto"}),d.animate({height:d.children(":eq ("+h+")").outerHeight()},b.autoHeightSpeed));if(b.preload&&d.find("img:eq("+h+")").length){a("."+b.container,c ).css({background:"url("+b.preloadImage+") no-repeat 50% 50%"});var z=d.find("img:eq("+h+")").attr("src")+"?"+(newDate).getTime();a("img",c).parent().attr("class")!="slides_control"?t=d.children(":eq(0)")[0].tagName.toLowerCas e():t=d.find("img:eq("+h+")"),d.find("img:eq("+h+")").attr("src",z).load(function(){d.find(t+":eq("+h+")").fadeIn( b.fadeSpeed,b.fadeEasing,function(){a(this).css({zIndex:5}),a("."+b.container,c).css({background:""}),o=!0,b.slid esLoaded()})})}elsed.children(":eq("+h+")").fadeIn(b.fadeSpeed,b.fadeEasing,function(){o=!0,b.slidesLoaded()});b.bigTarget&&(d.ch ildren().css({cursor:"pointer"}),d.children().click(function(){returnw("next",i),!1})),b.hoverPause&&b.play&&(d.bind("mouseover",function(){x()}),d.bind("mouseleave",function() {y()})),b.generateNextPrev&&(a("."+b.container,c).after('<a href="#" class="'+b.prev+'">Prev</a>'),a("."+b.prev,c).after('<a href="#" class="'+b.next+'">Next</a>')),a("."+b.next,c).click(function(a){a.preventDefault(),b.play&&y(),w("next",i)}),a(". "+b.prev,c).click(function(a){a.preventDefault(),b.play&&y(),w("prev",i)}),b.generatePagination?(b.prependPagin ation?c.prepend("<ul class="+b.paginationClass+"></ul>"):c.append("<ul class="+b.paginationClass+"></ul>"),d.children().each(function(){a("."+b.paginationClass,c).append('<li><ahref="#'+m+'">'+(m+1)+"</a></li>"),m++})):a("."+b.paginationClass+" li a",c).each(function(){a(this).attr("href","#"+m),m++}),a("."+b.paginationClass+"li:eq("+h+")",c).addClass(b.currentClass),a("."+b.paginationClass+" li a",c).click(function(){returnb.play&&y(),q=a(this).attr("href").match("[^#/]+$"),n!=q&&w("pagination",j,q),!1}),a("a.link",c).click(function() {returnb.play&&y(),q=a(this).attr("href").match("[^#/]+$")-1,n!=q&&w("pagination",j,q),!1}),b.play&&(v=setInterval(fu nction(){w("next",i)},b.play),c.data("interval",v))})},a.fn.slides.option={preload:!1,preloadImage:"/img/loading.gi f",container:"slides_container",generateNextPrev:!1,next:"next",prev:"prev",pagination:!0,generatePagination:!0,p rependPagination:!1,paginationClass:"pagination",currentClass:"current",fadeSpeed:350,fadeEasing:"",slideSpeed: 350,slideEasing:"",start:1,effect:"slide",crossfade:!1,randomize:!1,play:0,pause:0,hoverPause:!1,autoHeight:!1,aut oHeightSpeed:350,bigTarget:!1,animationStart:function(){},animationComplete:function(){},slidesLoaded:functio n(){}},a.fn.randomize=function(b){function c(){return Math.round(Math.random())-.5}return a(this).each(function(){var d=a(this),e=d.children(),f=e.length;if(f>1){e.hide();var g=[];for(i=0;i<f;i++)g[g.length]=i;g=g.sort(c),a.each(g,function(a,c){varf=e.eq(c),g=f.clone(!0);g.show().appendTo(d),b!==undefined&&b(f,g),f.remove()})}})}})(jQuery)$(function(){$('#slides').slides({preload: true,preloadImage: 'img/loading.gif',play: 5000,pause: 2500,hoverPause: true,animationStart: function(current){$('.caption').animate({bottom:-35},100);if (window.console && console.log) {// example return of current slide numberconsole.log('animationStart on slide: ', current);};},animationComplete: function(current){$('.caption').animate({bottom:0},200);if (window.console && console.log) {// example return of current slide numberconsole.log('animationComplete on slide: ', current);};},slidesLoaded: function() {$('.caption').animate({bottom:0},200);}});});HTML:<body><div id="container"><div id="example">&nbsp;<div id="slides"><div class="slides_container"><div class="slide"><a href=""target="_blank"><img src="img/1.jpg" class='img_css'></a><div class="caption"style="bottom:0"><p>农民工人1</p></div></div><div class="slide"><img src="img/2.jpg"class='img_css'><div class="caption"><p>农民工人2</p></div></div><div class="slide"><img src="img/3.jpg"class='img_css'><div class="caption"><p>黑洞</p></div></div><div class="slide"><img src="img/4.jpg"class='img_css'><div class="caption"><p>嘿嘿的</p></div></div></div><a href="#"class="prev"><img src="img/arrow-prev.png"width="24"height="43" alt="Arrow Prev"></a><a href="#"class="next"><img src="img/arrow-next.png"width="24"height="43" alt="Arrow Next"></a></div><img src="img/example-frame.png"width="739"height="341"alt="Example Frame" id="frame"></div></div></body>。

jQuery实现图片渐入渐出切换展示效果

jQuery实现图片渐入渐出切换展示效果

jQuery实现图⽚渐⼊渐出切换展⽰效果在这之前我们先看看我们要做的效果是什么样的:我们要图⽚在过“⼀定时间”后⾃动切换,在右下⾓处有⼩⽅块似数字1,2,3,4,这些数字是根据图⽚的个数⾃动出现的,当⿏标经过的时候数字颜⾊有⼀定的变化;下⾯我们来看看具体怎么实现。

第⼀步:先写简单的html页⾯<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript" src="../js/jquery.js" ></script><script type="text/javascript" src="scrollPic.js" ></script><link rel="stylesheet" href="scrollPic.css"></head><body><div class="pic-slider-io"><ul><li><img src="images/1.jpg" /></li><li><img src="images/2.jpg" /></li><li><img src="images/3.jpg" /></li><li><img src="images/4.jpg" /></li></ul></div></body></html>页⾯代码解析:⾸先建⽴scrollPic.html,scrollPic.js,scrollPic.css。

jQuery实现图片切换效果

jQuery实现图片切换效果

jQuery实现图⽚切换效果本⽂实例为⼤家分享了jQuery实现图⽚切换效果的具体代码,供⼤家参考,具体内容如下动画:点击左右按钮实现图⽚切换jQuery⽅法:animate(), stop(), first(), last(), siblings(), appendTo(), prependTo(), attr(), addClass(), removeClass(), eq()动画效果:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>图⽚切换</title><script src="../jquery.min.js"></script><style>*{margin: 0;padding: 0;list-style: none;}.main{margin: 50px auto;width: 538px;height: 405px;overflow: hidden;position: relative;}img{width: 538px;height: 405px;}.main .big{width: 3766px;height: 405px;}.big li{float: left;width: 538px;height: 405px;}.icon div{position: absolute;top: 180px;width: 40px;height: 35px;line-height: 35px;background: rgb(114,275,200);font-size:30px;font-weight: bold;text-align: center;color: #fff;}.left{left: 10px;border: 1px solid #003eff;border-top-right-radius: 5px;border-bottom-right-radius: 5px;}.right{right: 10px;border: 1px solid #003eff;border-top-left-radius: 5px;border-bottom-left-radius: 5px;}.small{position:absolute;bottom:10px;width: 538px;height:52px;}.small li{float: left;margin-left:4px;padding: 4px;width: 64px;height: 45px;}.small li.active{background: orange;}.small li img{width: 100%;height: 100%;}</style></head><body><div class="main"><ul class="big"><li title="0"><img src="images/1.jpg" alt="图⽚1"></li><li title="1"><img src="images/2.jpg" alt="图⽚1"></li><li title="2"><img src="images/3.jpg" alt="图⽚1"></li><li title="3"><img src="images/4.jpg" alt="图⽚1"></li><li title="4"><img src="images/5.jpg" alt="图⽚1"></li><li title="5"><img src="images/6.jpg" alt="图⽚1"></li><li title="6"><img src="images/7.jpg" alt="图⽚1"></li></ul><ul class="small"><li class="active"><img src="images/1.jpg" alt="图⽚1"></li><li><img src="images/2.jpg" alt="图⽚1"></li><li><img src="images/3.jpg" alt="图⽚1"></li><li><img src="images/4.jpg" alt="图⽚1"></li><li><img src="images/5.jpg" alt="图⽚1"></li><li><img src="images/6.jpg" alt="图⽚1"></li><li><img src="images/7.jpg" alt="图⽚1"></li></ul><div class="icon"><div class="left"><</div><div class="right">> </div></div></div><script type="text/javascript">$(document).ready(function () {var li_width=$(".big li").first().innerWidth();var index;//改变预览图⽚的类名function changeClass(){var index=$(".big li").attr("title");$(".small li").eq(index).addClass("active").siblings().removeClass("active");}//点击向右按钮,ul.big向左移动⼀张图⽚的宽度,显⽰下⼀张图⽚(此时第⼀张图⽚已经看不到)。

jQuery图片轮播滚动切换代码分享

jQuery图片轮播滚动切换代码分享

jQuery图⽚轮播滚动切换代码分享本⽂实例讲述了jQuery图⽚轮播滚动切换特效。

分享给⼤家供⼤家参考,具体如下:jQuery图⽚轮播滚动切换代码是⼀款简单的jquery四张图⽚轮播滚动切换效果代码,实现过程很简单。

运⾏效果图:------------------- -------------------⼩提⽰:浏览器中如果不能正常运⾏,可以尝试切换浏览模式。

在head区域引⼊CSS样式:<link rel="stylesheet" type="text/css" href="css/style.css" />为⼤家分享的jQuery图⽚轮播滚动切换代码如下<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>jQuery图⽚轮播滚动切换代码</title><script type="text/javascript" src="js/jquery-1.7.2.js"></script><script type="text/javascript" src="js/script.js"></script><link rel="stylesheet" type="text/css" href="css/style.css" /></head><body><div class="Div1"><b class="Div1_prev Div1_prev1" ><img src="images/lizi_img011.jpg" title="上⼀页" /></b><b class="Div1_next Div1_next1" ><img src="images/lizi_img012.jpg" title="下⼀页"/></b><div class="Div1_main"><div><span class="Div1_main_span1"><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span></div><div><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span></div><div><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span><span><a href="javascript:void(0)" class="Div1_main_a1"><img src="images/lizi_img007.jpg" /></a><a href="javascript:void(0)" class="Div1_main_a2">+详情点击</a></span></div></div></div></body></html>以上就是为⼤家分享的jQuery图⽚轮播滚动切换特效代码,希望⼤家可以喜欢,并应⽤到实践中。

jquery实现点击左右按钮切换图片

jquery实现点击左右按钮切换图片

jquery实现点击左右按钮切换图⽚本⽂实例为⼤家分享了jquery点击左右按钮切换图⽚的具体代码,供⼤家参考,具体内容如下当点击了右边的按钮后,图⽚向左移动,同理左边按钮。

css样式此处省略......直接进⼊到js代码中<div class="down-down-div"><div class="pics-frame"><div class="frame-first"><!--第⼀个div --><div id="left_btn" class="pic-button-left"><!--“ < ”按钮--><div style="padding-top: 70px;"><</div></div></div><!--第⼆个div --><div class="frame-second"><div class="frame-second-up"><div style="float: left;font-size: 10px;">&nbsp;&nbsp;&nbsp;本车型适⽤的精品配件:</div></div><div class="frame-second-down"><div class="frame-second-down-down"><!--图⽚集--><div class="frame-second-down-uppics"><img id="img0" style="width: 100%;height: 100%;" src="./images/accessories/t500.png" /></div><!--⽂字--><div class="frame-second-down-downtext">挡泥板</div></div><div class="frame-second-down-down"><!--图⽚集--><div class="frame-second-down-uppics"><img id="img1" style="width: 100%;height: 100%;" src="./images/accessories/t501.png" /></div><!--⽂字--><div class="frame-second-down-downtext">车窗侧⾬刷</div></div><div class="frame-second-down-down"><!--图⽚集--><div class="frame-second-down-uppics"><img id="img2" style="width: 100%;height: 100%;" src="./images/accessories/t502.png" /><!--⽂字--><div class="frame-second-down-downtext">车牌窗饰框</div></div><div class="frame-second-down-down"><!--图⽚集--><div class="frame-second-down-uppics"><img id="img3" style="width: 100%;height: 100%;" src="./images/accessories/t600.png" /> </div><!--⽂字--><div class="frame-second-down-downtext">地毯(七座)</div></div></div></div><!--第三个div --><div id="right_btn" class="frame-third"><!--“ > ”按钮--><div class="pic-button-right"><div style="padding-top: 70px;">></div></div></div></div></div><!--隐藏状态的图⽚集--><div id="imgs"><img src="images/accessories/t500.png" style="display: none;" /><img src="images/accessories/t501.png" style="display: none;" /><img src="images/accessories/t502.png" style="display: none;" /><img src="images/accessories/t600.png" style="display: none;" /><img src="images/accessories/t602.png" style="display: none;" /><img src="images/accessories/t603.png" style="display: none;" /><img src="images/accessories/t604.png" style="display: none;" /><img src="images/accessories/t605.png" style="display: none;" /><img src="images/accessories/t606.png" style="display: none;" /><img src="images/accessories/t607.png" style="display: none;" /><img src="images/accessories/t608.png" style="display: none;" /></div>$(function() {var images = [];var imgs = $("#imgs img");var index = 0;//展⽰的图⽚,长度为4var displayLength = $(".frame-second-down img").length;for(var i = 0; i < imgs.length; i++) {images.push(imgs[i]);}//相册左边按钮$("#left_btn").click(function() {if(index == 0) {alert("已经是第⼀张照⽚啦!");return;} else {for(var j = 0; j < displayLength; j++) {$("#img" + j).attr("src", images[index - 1 + j].src);}})//相册右边按钮$("#right_btn").click(function() {if(index == (imgs.length - displayLength)) {alert("已经是最后⼀张图⽚了!");return 0;} else {for(var j = 0; j < displayLength; j++) {$("#img" + j).attr("src", images[j + 1 + index].src);}index++;}})})以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

jQuery实现点击图片翻页展示效果的方法

jQuery实现点击图片翻页展示效果的方法

这篇文章主要介绍了jQuery实现点击图片翻页展示效果的方法,涉及jQuery操作图片的操作技巧,非常具有实用价值,需要的朋友可以参考下本文实例讲述了jQuery实现点击图片翻页展示效果的方法。

分享给大家供大家参考。

具体实现方法如下:代码如下:&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;基于jQuery实现的点击图片翻页展示效果&lt;/title&gt;&lt;meta http-equiv="content-type" content="text/html;charset=gb2312"&gt;&lt;style type="text/css"&gt;.div{width:240px;height:90px;z-index:0;position:absolute;left:10px;border:2px #3300FF solid;border:0px;color:#FFFFFF;margin-left:320px;}&lt;/style&gt;&lt;script type="text/javascript" src="/images/jquery1.3.2.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;$(function(){var z=-1;$("div").click(function(){$(this).animate({left:"350px"},1000,function(){$(this).css("zIndex",z--)}).animate({left:"10px"}, 1000);})});&lt;/script&gt;&lt;/head&gt;&lt;body&gt;若不能显示效果,则刷新页面可正常。

jQuery+CSS实现漂亮的四屏焦点图片幻灯切换效果

jQuery+CSS实现漂亮的四屏焦点图片幻灯切换效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><title>jQuery+CSS实现漂亮的四屏焦点图片幻灯切换效果丨芯晴网页特效丨</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><!--把下面代码加到<head>与</head>之间--><style type="text/css">BODY {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12px; BACKGROUND: #ffffff; PADDING-BOTTOM: 0px; MARGIN: 0px; COLOR: #000000; PADDING-TOP: 0px; FONT-FAMILY: "宋体", "新宋体", Arial, Helvetica, sans-serif}A {FONT-SIZE: 12px; COLOR: #000000; TEXT-DECORATION: none}A:link {COLOR: #000000}A:visited {COLOR: #333333}A:hover {COLOR: #f5811d}A:active {COLOR: #000000}UL {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; LIST-STYLE-TYPE: none}LI {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px; LIST-STYLE-TYPE: none}IMG {BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px}#myjQuery {PADDING-RIGHT: 5px; PADDING-LEFT: 5px; BACKGROUND: #b7a490; PADDING-BOTTOM: 5px; OVERFLOW: hidden; WIDTH: 488px; PADDING-TOP: 5px; POSITION: relative; HEIGHT: 275px}#myjQueryContent {BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 1px solid; OVERFLOW: hidden; BORDER-LEFT: #ffffff 1px solid; WIDTH: 486px; BORDER-BOTTOM: #ffffff 1px solid; HEIGHT: 224px }#myjQueryContent DIV {POSITION: absolute; HEIGHT: 224px;left:6px;top:6px;}#myjQueryContent .smask {Z-INDEX: -1}#myjQueryContent IMG {WIDTH: 486px; HEIGHT: 224px}#myjQueryNav {BORDER-TOP: #ffffff 2px solid; DISPLAY: block; OVERFLOW: hidden; WIDTH: 488px; HEIGHT: 47px }#myjQueryNav LI {DISPLAY: block; FLOAT: left; WIDTH: 122px; CURSOR: pointer; PADDING-TOP: 7px; HEIGHT: 40px; TEXT-ALIGN: center}#myjQueryNav .nbg {BACKGROUND: none transparent scroll repeat 0% 0%}#myjQueryNav A {DISPLAY: block; Z-INDEX: 12; MARGIN: 0px auto; TEXT-TRANSFORM: uppercase; WIDTH: 85px; COLOR: #ffffff; LINE-HEIGHT: 16px; POSITION: relative; HEIGHT: 47px}#myjQueryNav .current {BACKGROUND: none transparent scroll repeat 0% 0%}#myjQueryNav .current A {COLOR: #f6821e}#myjQuery #flow {MARGIN-TOP: -47px; Z-INDEX: 10; BACKGROUND: url(/images/20110914/fcurrent.gif); LEFT: 5px; WIDTH: 122px; POSITION: absolute; HEIGHT: 47px}</style><script src="/images/jquery-1.2.6.pack.js" type="text/javascript"></script><script type="text/javascript">jQuery(function($){var index = 0;$('<div id="flow"></div>').appendTo("#myjQuery");//滑动导航改变内容$("#myjQueryNav li").hover(function(){if(MyTime){clearInterval(MyTime);}index = $("#myjQueryNav li").index(this);MyTime = setTimeout(function(){ShowjQueryFlash(index);$('#myjQueryContent').stop();} , 400);}, function(){clearInterval(MyTime);MyTime = setInterval(function(){ShowjQueryFlash(index);index++;if(index==4){index=0;}} , 3000);});//滑入停止动画,滑出开始动画.$('#myjQueryContent').hover(function(){if(MyTime){clearInterval(MyTime);}},function(){MyTime = setInterval(function(){ShowjQueryFlash(index);index++;if(index==4){index=0;}} , 3000);});//自动播放varMyTime = setInterval(function(){ShowjQueryFlash(index);index++;if(index==4){index=0;}} , 3000);});function ShowjQueryFlash(i) {$("#myjQueryContent div").eq(i).animate({opacity: 1},1000).css({"z-index": "1"}).siblings().animate({opacity: 0},1000).css({"z-index": "0"});$("#flow").animate({ left: i*122+5 +"px"}, 300 ); //滑块滑动$("#myjQueryNav li").eq(i).addClass("current").siblings().removeClass("current");}</script></head><body>预览效果时左下角会提示错误,而且看不到效果,刷新一下就可以看到效果了;当然,在实际使用中,不会出现这样的问题。

用jquery实现图片的切换与随机显示 (1)

用jquery实现图片的切换与随机显示 (1)

用jquery实现图片的切换与随机显示本例所要实现的效果如下:1单击按钮,能够切换图片切换之前,如图1所示:图1切换之后,如图2所示:图22图片每次切换后,位置是随机变化的切换之前,如图3所示:图3切换之后,如图4所示:图43第一次所有图片加载时,效果是淡入的,加载完之后的所有切换淡入效果消失。

(由于此效果难截图,所以不能显示)4鼠标移上去,图片变大,下边显示有关于图片的描述信息如图5所示:图5下边有关此效果的具体实现步骤。

前提将html,css样式,所需图片,准备好,源文件放在源文件文件夹下边。

为操作方便,布局采用的是table+div。

本例图片分两组,一组显示12张图片。

①单击按钮,切换图片打开浏览器时,图片并未直接加载在页面中,而是通过调用js代码将第一组图片一张张加载进去。

关键代码如下$(document).ready(function(){for(var i=0;i<=11;i++){$("#i"+i).attr("src","imgs/0"+i+".jpg").hide().fadeIn(2000);//通过图片id获取图片路径}})补充:为方便加载图片,图片的命名规则是00,01,02 (011)10,11,12…111;这样做的好处是通过图片名字的第一位数判断图片所属的组数,由于浏览器是第一次加载图片,显示的是第一组,所以上述代码图片的第一位直接是0.当单击按钮时,会触发randomImage()事件,即切换图片。

关键代码如下: function randomImage(){count++; //用来记录单击按钮的次数,设为全局变量,初始值为0count=count%2;//遍历完一遍图片后,将count置为0,可以循环切换图片,并且能够通过count识别应该加载第几组图片,本例用的是两组图片,如果是多组图片,此方法照样可以用。

jquery简单图片切换显示效果实现方法

jquery简单图片切换显示效果实现方法

jquery简单图⽚切换显⽰效果实现⽅法本⽂实例讲述了jquery简单图⽚切换显⽰效果实现⽅法,分享给⼤家供⼤家参考。

具体实现⽅法如下:复制代码代码如下:<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /><title>jquery图⽚切换效果</title><script type="text/javascript" src="jquery-1.8.2.min.js"></script><script type="text/javascript">$(function(){$("#item li:not(:first)").css("display","none");//只显⽰第⼀张图⽚,其它隐藏var bb = $("#item li:last");var aa = $("#item li:first");setInterval(function(){if(bb.is(":visible")){aa.fadeIn(1000).addClass("in");bb.hide();}else{$("#item li:visible").addClass("in");$("#item li.in").next().fadeIn(1000);$("#item li.in").fadeOut(1000).removeClass("in");}},3000);});</script></head><style type="text/css">li{list-style:none;display:block;width:500px;border:1px solid #ccc;padding:5px;}.in{display:block;}</style><body><ul id="item"><li><img src="./images/11_b.jpg" /></li><li><img src="./images/22_b.jpg" /></li><li><img src="./images/33_b.jpg" /></li><li><img src="./images/44_b.jpg" /></li></ul></body></html>希望本⽂所述对⼤家的jQuery程序设计有所帮助。

JQuerySwitchable图片切换播放插件

JQuerySwitchable图片切换播放插件

JQuerySwitchable图片切换播放插件JQuery Switchable 图片切换播放插件IntroductionjQuery.Switchable是一款整合了Tabs、Slide、Scrollable等常见UI组件的jQuery插件。

它有简单易用的API、可灵活配置的Configuration,支持自定义Effect,支持自主开发Plugin。

下面是jQuery.Switchable的几个亮点:1.在当前 trigger 中 mouseenter/mouseleave, click 不触发2.鼠标快速滑过非当前 trigger, 不触发3.mouseenter 到非当前 trigger, 停留时间到达延迟时,触发4.click trigger/panel, 立即触发5.beforeSwitch/onSwitch 事件的触发6.panel 内的锚链触发7.无法获取 trigger 时,自动创建 triggerConfiguration下面是构建jQuery.Switchable的基本格式:1$("trigger-container-selector").switchable("panel-selector", {2triggerType: "mouse", // or click3effect: "default",4circular: false5});trigger-container-selector是trigger的容器,使用jQuery Selector 获取。

trigger默认是<a>标签,如果没有获取到,将自动创建。

1st argument: panel-selector是具体的panel元素,使用jQuery Selector 获取,比如:#panel > img。

2st argument: configuration可以是一个function,或者是一个object,甚至可以省略。

基于jquery实现左右按钮点击的图片切换效果

基于jquery实现左右按钮点击的图片切换效果

基于jquery实现左右按钮点击的图⽚切换效果jQuery可以制作出与Flash媲美的动画效果,这点绝对⽏庸置疑,本⽂将通过实例演⽰⼀个左右按钮点击的图⽚切换效果。

⼀、最终效果⼆、功能分析1、需求分析点击左边pre按钮,显⽰前⾯三个图⽚,点击右边的next按钮,显⽰后⾯的⼀组(三个)图⽚。

初始化只显⽰next按钮,到最后⼀组只显⽰pre按钮,中间过程两按钮都显⽰。

2、html结构分析<div class="activity" id="activity-slide"><a href="javascript:void(0)" class="pg_left ps_pre"></a><a href="javascript:void(0)" class="pg_right ps_next" ></a><ul class="clearfix"><li><a href="javascript:;"><img src="images/activity01-1410.jpg"></a></li><li><a href="javascript:;"><img src="images/activity02-1410.jpg"></a></li><li><a href="javascript:;"><img src="images/activity03-1410.jpg"></a></li><li><a href="javascript:;"><img src="images/activity03-1410.jpg"></a></li><li><a href="javascript:;"><img src="images/activity02-1410.jpg"></a></li></ul></div>#activity-slide是整个幻灯的⼊⼝,后⾯会将其作为参数来调⽤幻灯功能。

使用jQuery做左右点击切换图片的手动图片轮播效果

使用jQuery做左右点击切换图片的手动图片轮播效果

使⽤jQuery做左右点击切换图⽚的⼿动图⽚轮播效果代码和个⼈解析:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><style>img {width: 300px;height: 300px;} /* 这⾥设置样式只是为了使图⽚在点击时不会出现图⽚⼤⼩不⼀的情况,img可以统⼀设置页⾯中所有的图⽚⼤⼩ */</style></head><body><img src="./img/1.jpg" /> <!-- 这⾥有⼀个要注意的点,设置相对的路径,图⽚的名称要变成连贯的数字序号排列 --><button>上⼀张</button><button>下⼀张</button><script src="./js/jquery-3.4.1.js"></script> // 引⼊jQuery⽂件<script>$(function() {var t = 1; //定义⼀个变量⽤来进⾏判断//上⼀张的按钮实现$("button").eq(0).click(function() { //这⾥的eq()是相当于是索引,从0开始计数,就是获取第⼀个button按钮t += 1; //我这⾥是简写了,展开就是 t=t+1 ,当点击第⼆次的时候,就+1,把图⽚变成第⼆张,再点击,就再+1 if (t > 4) { //这⾥的if判断,也可以说是充当⼀个for循环,我只有4张图⽚,当我点击到最后⼀张时,就是说图⽚已经到我没有的第五张图时, //就把t的值改为 1 就到了我的第⼀张图⽚,类似于⼀个for循环t = 1}$("img").attr("src", "img/" + t + ".jpg") //这⾥是⼀个类似字符串的拼接,t 是⼀个动态的数据})//下⼀张的按钮实现$("button").eq(1).click(function() {t -= 1; //展开 t=t-1if (t < 1) {t = 4}$("img").attr("src", "img/" + t + ".jpg")})//下⼀张按钮的实现与上⼀张的思路和逻辑是⼀样,判断就是把上⼀张按钮的条件反过来//值得注意的是eq()的索引值的起始值,还有把判断条件理清楚,然后就是图⽚的命名})</script></body></html><!-- ⼀起加油努⼒学习前端知识吧 -->。

Jquery刷新页面背景图片随机变换的实现方法

Jquery刷新页面背景图片随机变换的实现方法
首页有一个导航页面要实现滚动效果索性就仿造别人的效果自己做了一个大体上还行看起来还是比较流畅的现滚动效果脚本代码如下感兴趣的朋友可以参考下
Jquery刷 新 页 面 背 景 图 片 随 机 变 换 的 实 现 方 法
使用方法:下载jquery-1.9.1.js,然后设置CSS,图片文件放在images/new_feed/目录下,图片命名格式为bg_x.jpg,修改随机 数产生范围
}); </script;style> body{
padding:0; background-attachment: fixed; background-clip: border-box; background-color: #666666; background-origin: padding-box; background-position: center top; background-repeat: no-repeat; background-size: cover; width: 100%; background-image:url("");} </style>
复制代码 代码如下:
<script type="text/javascript"> $(document).ready(function(){ var random_bg=Math.floor(Math.random()*6+1); var bg='url(images/new_feed/bg_'+random_bg+'.jpg)'; $("body").css("background-image",bg);

jquery图片切换实例分析

jquery图片切换实例分析

本文实例讲述了jquery图片切换实现方法。

分享给大家供大家参考。

具体如下:&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"""&gt;&lt;html xmlns=""&gt;&lt;head&gt;&lt;script language="javascript" src="inc/jquery-1.4.2.js"&gt;&lt;/script&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;&lt;title&gt;无标题文档&lt;/title&gt;&lt;/head&gt;&lt;style type="text/css"&gt;#butt div{width:122px; height:32px; float:left; text-align:center;}&lt;/style&gt;&lt;script language="javascript"&gt;function tab_q(now_id){if(now_id == null){//alert($("#butt").find("div:visible").attr("id"))c_show_id = $("#cont").find("div:visible").attr("id");//此时显示按钮的ID名称nums_id = c_show_id.substring(1,3);//截取B1后面的1,作为字符串放到C后面b_show_id = "b"+ nums_id;//此时显示内容的ID名称nums_next = parseInt(nums_id)+1//alert(nums_next)if(nums_next&lt;=8)//如果到最后一个的话,那么就要跳回第一个{}else{nums_next = 1}}else{nums_next = now_id.substring(1,3);}$("#cont div").hide();//让所有的上面的div中的图片消失。

jquery实现图片切换功能

jquery实现图片切换功能

<html><head><title>javaScript定时切换图片</title><script src="jquery.js"></script><style type="text/css">.image{cursor:pointer;width:300px;height:250px;filter:alpha(opacity=0);-moz-opacity: .5;opacity: .5;border:0;margin:10px;}.post{color: rgba(0,0,0,1);background-color: rgba(255,255,255,0);display:block;padding: 0px,0px,0px,0px;}.weizhi1{position:fixed;left:250px;top:230px;}.weizhi2{position:fixed;left:270px;top:230px;}.weizhi3{position:fixed;left:290px;top:230px;}</style></head><body><img class="image" id="ma" src="1.jpg" /><script language=javascript>var a=2;var timer=setInterval("s()",3000);function s(){if(a>3){a=1;}if(a==1){$(document).ready(function(){$(".image").attr("src","1.jpg");});$("#but1").css("background-color","blue");$("#but3").css("background-color","");$("#but2").css("background-color","");}if(a==2){// alert("2");$(document).ready(function(){$(".image").attr("src","2.jpg");});$("#but1").css("background-color","");$("#but3").css("background-color","");$("#but2").css("background-color","blue");}if(a==3){// alert("3");$(document).ready(function(){$(".image").attr("src","3.jpg");});$("#but2").css("background-color","");$("#but3").css("background-color","blue");$("#but1").css("background-color","");}a++;};</script><script type="text/javascript"> $(document).ready(function(){$("#but1").click(function(){$(".image").attr("src","1.jpg");$("#but1").css("background-color","blue");$("#but2").css("background-color","");$("#but3").css("background-color","");a = 2;});});$(document).ready(function(){$("#but2").click(function(){$(".image").attr("src","2.jpg");$("#but2").css("background-color","blue");$("#but1").css("background-color","");$("#but3").css("background-color","");a=3;});});$(document).ready(function(){$("#but3").click(function(){$(".image").attr("src","3.jpg");$("#but1").css("background-color","");$("#but2").css("background-color","");$("#but3").css("background-color","blue");a=1;});});</script><button class="post weizhi1" id="but1" style="background:#0000ff">1</button> <button class="post weizhi2" id="but2" >2</button><button class="post weizhi3" id="but3">3</button></body></html>。

jQuery实现的鼠标滑过切换图片代码实例

jQuery实现的鼠标滑过切换图片代码实例

jQuery实现的⿏标滑过切换图⽚代码实例
jQuery实现的⿏标滑过切换图⽚代码实例:
有时候⽹页需要这样的简单效果,那就是当⿏标滑过默认图⽚的时候,能够实现图⽚的切换,可能在实际应⽤中,往往没有这么简单,不过⼤家可以⾃⾏扩展⼀下,下⾯简单介绍⼀下次效果。

html静态代码如下:
<body>
<img src="images/mayi.jpg"/>
</body>
jquery切换代码:
$(document).ready(function(){
var newImage=new Image();
var oldImage=$('img').attr('src');
newImage.src='images/new.jpg';
$('img').hover(function(){
$('img').attr('src',newImage.src);
},
function(){
$('img').attr('src',oldImage);
})
})
以上代码是实现切换的核⼼,原理很简单,就是为图⽚的注册hover事件处理函数,当⿏标悬浮的时候,修改图⽚的src属性值即可。

图片轮播(左右切换)--JS原生和jQuery实现

图片轮播(左右切换)--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 进⾏定位。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

下面小编就为大家带来一篇完美JQuery图片切换效果的简单实现。

小编觉得挺不错的,现在就分享给大家,也给大家做个参考。

css:body { font-family:"Microsoft Yahei"; }body,ul,li,img,h3,dl,dd,dt,h1{margin:0px;padding:0px;list-style:none;} &nbsp;img{vertical-align: top;}/***大图切换***/.scroll_view{margin: 0px auto;overflow:hidden;position: relative;}.photo_view li{position:absolute;width: 100%;}.photo_view li em,.photo_view li h3{position: absolute;bottom: 0px;z-index: 1;height: 35px;line-height: 35px;width: 100%;left: 0px;}.photo_view li em{z-index: 1;background:rgba(0,0,0,0.5);filter: progid:DXImageTransform.Microsoft.gradient( GradientType = 0,startColorstr = '#50000000',endColorstr = '#50000000');_background:#000;}.photo_view li h3{z-index: 2;text-indent: 1em;font-weight: normal;}.photo_view li h3 a{color:#fff;}.photo_view li h3 a:hover{color:#f60;}.small_photo{position: absolute;bottom: 40px;right: 10px;cursor: pointer;z-index: 4;}.small_photo li {float: left;padding-right: 10px;}.small_photo li img{width: 80px;height: 35px;border: solid 2px #ccc;border-radius: 2px;} .small_photo li.active img{border: solid 2px #f60;}html:&lt;!-- start:大图切换--&gt;&lt;div class="scroll_view"&gt;&nbsp; &lt;ul class="photo_view"&gt;&nbsp; &nbsp; &lt;li&gt;&lt;img src="images/ad1.jpg" alt="" class="" /&gt;&lt;em&gt;&lt;/em&gt;&lt;h3&gt;&lt;a href="javascript:void(0);"&gt;图片效果1&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;&nbsp; &nbsp; &lt;li&gt;&lt;img src="images/ad2.jpg" alt="" class="" /&gt;&lt;em&gt;&lt;/em&gt;&lt;h3&gt;&lt;a href="javascript:void(0);"&gt;图片效果2&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;&nbsp; &nbsp; &lt;li&gt;&lt;img src="images/ad3.jpg" alt="" class="" /&gt;&lt;em&gt;&lt;/em&gt;&lt;h3&gt;&lt;a href="javascript:void(0);"&gt;图片效果3&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;&nbsp; &nbsp; &lt;li&gt;&lt;img src="images/ad4.jpg" alt="" class="" /&gt;&lt;em&gt;&lt;/em&gt;&lt;h3&gt;&lt;a href="javascript:void(0);"&gt;图片效果4&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;&nbsp; &lt;/ul&gt;&nbsp; &lt;ul class="small_photo"&gt;&lt;/ul&gt;&lt;/div&gt;&lt;!-- End:大图切换--&gt;js:$.fn.extend({ &nbsp;&nbsp; imgScroll:function(options){ &nbsp; &nbsp;&nbsp; &nbsp; var def={phtot_parent:$(".scroll_view"),photo_view:$(".photo_view"),small_photo:$(".small_photo") ,speed:800,isauto:true,width:800,height:349},&nbsp; &nbsp; &nbsp; opt=$.extend({},def,options),&nbsp; &nbsp; &nbsp; $photo_view=opt.photo_view,&nbsp; &nbsp; &nbsp; $small_photo=opt.small_photo,&nbsp; &nbsp; &nbsp; speed=opt.speed,&nbsp; &nbsp; &nbsp; isauto=opt.isauto,&nbsp; &nbsp; &nbsp; index=0,&nbsp; &nbsp; &nbsp; _length=$photo_view.find("li").length,&nbsp; &nbsp; &nbsp; strTime=null;&nbsp; &nbsp; opt.phtot_parent.css({width:opt.width,height:opt.height});&nbsp; &nbsp; $photo_view.find("li:not(:first)").hide()//.find("img").hide();&nbsp; &nbsp; $photo_view.find("li").each(function(i){&nbsp; &nbsp; &nbsp; $small_photo.append('&lt;li&gt;&lt;img src="'+$(this).find("img").attr("src")+'" alt="" class="" /&gt;&lt;/li&gt;');&nbsp; &nbsp; })&nbsp; &nbsp; $small_photo.find("li:first").addClass("active");&nbsp; &nbsp; //小图鼠标动作&nbsp; &nbsp; $small_photo.find("li").bind("mouseenter",function(){ &nbsp;&nbsp; &nbsp; &nbsp; clearInterval(strTime);&nbsp; &nbsp; &nbsp; if(index!=$(this).index()){&nbsp; &nbsp; &nbsp; &nbsp; index=$(this).index(); &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; animate(index)&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }).bind("mouseleave",function(){ &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if(isauto){&nbsp; &nbsp; &nbsp; &nbsp; start(); &nbsp;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; //大图悬停动作&nbsp; &nbsp; $photo_view.find("li").bind("mouseenter",function(){ &nbsp;&nbsp; &nbsp; &nbsp; clearInterval(strTime); &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; }).bind("mouseleave",function(){ &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if(isauto){&nbsp; &nbsp; &nbsp; &nbsp; start(); &nbsp;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });&nbsp; &nbsp; //自动播放&nbsp; &nbsp; if(isauto){&nbsp; &nbsp; &nbsp; start(); &nbsp;&nbsp; &nbsp; }&nbsp; &nbsp; //启动自动播放&nbsp; &nbsp; function start(){&nbsp; &nbsp; &nbsp; strTime=setInterval(function(){&nbsp; &nbsp; &nbsp; &nbsp; index &gt;= _length-1 ? index=0 : index++;&nbsp; &nbsp; &nbsp; &nbsp; animate(index);&nbsp; &nbsp; &nbsp; },speed);&nbsp; &nbsp; }&nbsp; &nbsp; //动画效果&nbsp; &nbsp; function animate(_index){//console.log(_index)&nbsp; &nbsp; &nbsp; $small_photo.find("li").eq(_index).addClass('active').siblings().removeClass("active");//改变小图导航样式&nbsp; &nbsp; &nbsp; $photo_view.find("li").eq(_index).css("z-index",1).siblings().css("z-index",0);//控制absolute的层级&nbsp; &nbsp; &nbsp; $photo_view.find("li").eq(_index).show().find("img").css({"opacity": 0}); &nbsp;//装大图的opacity设置为0 &nbsp;&nbsp; &nbsp; &nbsp; $photo_view.find("li").eq(_index).find("img").animate({opacity:1},300,function(){ &nbsp; &nbsp; &nbsp; &nbsp; $(this).removeAttr("style");//动画之后删除opacity&nbsp; &nbsp; &nbsp; &nbsp; $photo_view.find("li").eq(_index).show().siblings().hide();//显示大图&nbsp;&nbsp; &nbsp; &nbsp; });//展示当前显示动画&nbsp; &nbsp; }&nbsp; }});&lt;script type="text/javascript"&gt;&nbsp; $(function(){$("scroll_view").imgScroll({photo_view:$(".photo_view"),small_photo:$(".small_ph oto"),speed:3000,isauto:true});&nbsp;&nbsp; })&lt;/script&gt;以上这篇完美JQuery图片切换效果的简单实现就是小编分享给大家的全部内容了,希望能给大家一个参考。

相关文档
最新文档