首页 > web前端 > js教程 > 正文

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

php中文网
发布: 2016-05-16 17:00:18
原创
1532人浏览过

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

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

源代码如下:

jQuery的视觉差效果图片左右滚动轮播特效
jQuery的视觉差效果图片左右滚动轮播特效

jQuery视觉差效果图片左右滚动轮播特效

jQuery的视觉差效果图片左右滚动轮播特效 56
查看详情 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>


相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号