jQuery实现的多屏图像图层切换效果实例
网络编程 2021-07-04 21:47www.168986.cn编程入门
这篇文章主要介绍了jQuery实现的多屏图像图层切换效果,可实现多个图层的点击切换效果,设计jQuery鼠标事件及样式的操作技巧,需要的朋友可以参考下
本文实例讲述了jQuery实现多屏图像图层切换效果的方法。分享给大家供大家参考。具体实现方法如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.6.2.min.js"></script> <style type="text/css"> ul{list-style:none;margin:0;padding:0;} li{float:left;} .Xing_focus{ width:875px; height:800px; overflow:hidden;border:1px solid red; } .Xing_focus ul{ width:3500px; } .bnt { float:left;width:300px;height:20px; border:1px solid red; } .bnt li{ width:18px;height:18px; background:red; cursor:pointer; margin-right:10px;float:left; } .bnt .sli{ background:blue; } .next{ width:100px;height:100px; background:#990000;float:left; cursor:pointer; } .pre{ width:100px;height:100px; background:#009;float:left; cursor:pointer;margin-right:30px; } .list1{ width:875px;height:500px;background:red; } .list2{ width:875px;height:500px;background:black; } .list3{ width:875px;height:500px;background:pink; } .list4{ width:875px;height:500px;background:blue; } </style> </head> <body> <div class="Xing_focus" id="box"> <ul class="imgs" id="actor"> <li class="list1"> <img src="http://.baidu./img/baidu_sylogo1.gif" /> </li> <li class="list2"> <img src="http://.baidu./img/baidu_sylogo1.gif" /> </li> <li class="list3"> <img src="http://.baidu./img/baidu_sylogo1.gif" /> </li> <li class="list4"> <img src="http://.baidu./img/baidu_sylogo1.gif" /> </li> </ul> <ul class="bnt" id="bnt"> </ul> <div class="pre" id="pre">上一张</div> <div class="next" id="next">下一张</div> </div> <script type="text/javascript"> $(window).load(function() { var liW = $("#actor li:first").width(); var liL = $("#actor li").length; //alert(liW) var lis = $("#actor li").length; for(i=0;i<lis;i++){ $("#bnt").append("<li></li>") $("#bnt li:first").addClass("sli"); }; $("#bnt li").each(function(index) { $(this).click(function(){ if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":-indexliW},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li").eq(index).addClass("sli"); }); }; }); }); settime=window.setInterval(atuoScroll,2000); $("#box").hover(function(){ window.clearInterval(settime); },function(){ settime=window.setInterval(atuoScroll,2000); }); //////////////////////////////////////// $("#next").click(function(){ var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==-((liL-1)liW)&&$("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":0+"px"},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:first").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":ulM-liW+"px"},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }); //////////////////////////////////////// $("#pre").click(function(){ var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==0&&$("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":-2625+"px"},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:last").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").animate({"marginLeft":ulM+liW+"px"},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }); ////////////////////////////////////// });//END function atuoScroll(){ var liW = $("#actor li:first").width(); var liL = $("#actor li").length; var ulM =parseInt( $("#actor").css("margin-left")); if(ulM==-((liL-1)liW)&&$("#actor").is(":animated")==false){ $("#actor").s(); $("#actor").animate({"marginLeft":0},500,function(){ $("#bnt li").removeClass("sli"); $("#bnt li:first").addClass("sli"); }); } else if($("#actor").is(":animated")==false){ $("#actor").s(); $("#actor").animate({"marginLeft":ulM-liW},500,function(){ var ulM =parseInt( $("#actor").css("margin-left")); var num = -ulM/liW $("#bnt li").removeClass("sli"); $("#bnt li").eq(num).addClass("sli"); }); }; }; </script> </body> </html>
希望本文所述对大家的jQuery程序设计有所帮助。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指