Maison > interface Web > js tutoriel > le corps du texte

利用jquery写的左右轮播图特效_jquery

WBOY
Libérer: 2016-05-16 17:00:18
original
1261 Les gens l'ont consulté

最近不是很忙,练习写了一个轮播图效果,虽然效果跟功能上貌似是没问题,但是我认为在许多东西上面都有待改进,在前端这个职位上我还有很远的路要走,当然要学的东西还有很多,这里仅仅对自己最近研究js的一个记录,我相信以后能写出更好的

将jquery框架的链接跟图片替换就可以看到效果了

源代码如下:

复制代码 代码如下:





轮播图





<script> <BR>var b_width = 1000; // 大图的宽度 <BR>var speed = 500; // 图片向左移动速度 <BR>var s_time = 3000 //图片自动滚动速度 <BR>var pic_li = $("#lunbo_pic").children("li"); <BR>$(document).ready(function(e) { <BR>var $ul_width= pic_li.width() * pic_li.length; //轮播图的宽度 <BR>$("#lunbo_pic").width($ul_width); <BR>var small_width = $(".lunbo_curso>a").width() * $(".lunbo_curso>a").length; <BR>$(".lunbo_curso").width(small_width); <BR>$(".lunbo_curso").css("margin-left",-small_width/2); <BR>}); <br><br><br><br>$(document).live("click",function(e){ <BR>$target = $(e.target); <BR>var id = $target.attr('id'); <BR>if($target.is("a") && $target.parent($("#lunbo_curso")) ){ <BR>$target.addClass("small_xz").siblings().removeClass('small_xz'); <BR>var mar_lf = parseInt($target.index() * b_width); <BR>$("#lunbo_pic").animate({ <BR>left : -mar_lf <BR>},speed); <BR>} <BR>if(id == "arr_l"){ <BR>prePage(); <BR>} <BR>if(id == "arr_r"){ <BR>nextPage(); <BR>} <BR>}); <BR>//上一个 <BR>function prePage(){ <BR>if($(".small_xz").index() == 0){ <BR>$("#lunbo_pic").css("left",-4000); <BR>$("#lunbo_pic").animate({ <BR>"left": -parseInt(pic_li.length *b_width - b_width) <BR>},speed); <BR>$("#lunbo_curso>a").eq(pic_li.length - 1).addClass("small_xz").siblings().removeClass("small_xz"); <BR>$(".small_xz").index() == pic_li.length - 1; <BR>}else{ <BR>$("#lunbo_curso>a").eq($(".small_xz").index()-1).addClass("small_xz").siblings().removeClass("small_xz"); <BR>var mar_lf2 = parseInt($("#lunbo_pic").css("left")) + b_width; <BR>$("#lunbo_pic").animate({ <BR>"left": mar_lf2 <BR>},speed); <BR>} <BR>} <BR>//下一个 <BR>function nextPage(){ <BR>if($(".small_xz").index() == pic_li.length -1){ <BR>$("#lunbo_pic").css("left",0); <BR>/*$("#lunbo_pic").animate({ <BR>"left": 0 <BR>},speed);*/ <BR>$("#lunbo_curso>a").eq(0).addClass("small_xz").siblings().removeClass("small_xz"); <BR>$(".small_xz").index() == 0; <br><br>}else{ <br><br>$("#lunbo_curso>a").eq($(".small_xz").index() + 1).addClass("small_xz").siblings().removeClass("small_xz"); <BR>var mar_lf2 = parseInt($("#lunbo_pic").css("left")) - b_width; <BR>$("#lunbo_pic").animate({ <BR>"left": mar_lf2 <BR>},speed); <BR>} <BR>} <br><br>function picRun(){ <BR>nextPage(); <BR>} <BR>intervalTime = setInterval(picRun,s_time); <br><br>$("#pic_carousel").on("mouseover",function(){ <BR>clearInterval(intervalTime); <BR>}); <BR>$("#pic_carousel").on("mouseout",function(){ <BR>intervalTime = setInterval(picRun,s_time);; <BR>}); <br><br></script>


Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!