jQuery插件實(shí)現(xiàn)帶圓點(diǎn)的焦點(diǎn)圖片輪播切換
這次分享的代碼是jQuery插件,HovertreeImg是一個(gè)圖片輪播jquery插件,使用方便,可以設(shè)置大小,圓點(diǎn)位置等,代碼簡(jiǎn)潔
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <base target="_blank" /> <meta charset="utf-8" /> <style>#img {width:768px;height:66px;overflow:hidden} #img img{width:100%;height:100%;} #img #imgcontent{display:none}a{color:blue}</style> </head> <body> <div id="img"> <a href="/h/bjaf/hovertreeimg.htm" title="Img" target="_blank"><img src="/jq/img/img.jpg" alt="Img插件" /></a> <div id="imgcontent"> <a href="/h/bjaf/easysector.htm" title="HTML5百分比餅圖" target="_blank"><img src="/themes/img/easysector.gif" alt="EasySector插件" /></a> <a href="/texiao/game/" title="見(jiàn)縫插針" target="_blank"><img src="/themes/img/jfcz.gif" alt="見(jiàn)縫插針" /></a> </div> </div> <div> <br /><br /> </div> <script src="/ziyuan/jquery/jquery-1.12.0.min.js"></script> <script src="/jq/hovertreeimg/jquery.img.js"></script> <script> $("#img").hovertreeimg({ "h_circlePosition": "",//left,right,center "h_width": 768, "h_height": 66, "h_borderColor":"silver", "h_circleWidth": 14 }); </script> </body> </html>
jquery.img.js
/*! * HovertreeImg(jQuery Plugin) * version: 1.0.0 * Copyright (c) 2016 HoverTree */ (function ($) { $.fn.hovertreeimg = function (options) { var settings = $.extend({ h_time:"3000",//切換時(shí)間 h_borderColor: "transparent",//邊框顏色 h_width: "500",//寬度 h_height: "200",//高度 h_circleWidth: "18",//方框邊長(zhǎng) h_circleColor:"silver",//圓點(diǎn)顏色 h_currentCircleColor: "red",//當(dāng)前圓點(diǎn)顏色 h_circlePosition:"right"http://圓點(diǎn)位置 }, options); var h_hovertreeimg = $(this); if (h_hovertreeimg.length < 1) return; h_hovertreeimg.css({ "position": "relative", "border":"solid 1px "+ settings.h_borderColor , "width": settings.h_width, "height": settings.h_height , "overflow": "hidden" }) var h_hovertreeimgcontent = h_hovertreeimg.find(">div#hovertreeimgcontent"); h_hovertreeimgcontent.hide(); var h_hovertreeimgcurrent = h_hovertreeimg.find(">a"); h_hovertreeimgcurrent.wrap("<div id='replaceframe'></div>"); h_replaceFrame = h_hovertreeimg.find("#replaceframe").css({ "width": "100%", "height": "100%" }); //構(gòu)造圓點(diǎn)框 $('<div class="hovertreeimgpoint"></div>').appendTo(h_hovertreeimg); var h_hovertreeimgpoint = h_hovertreeimg.find(".hovertreeimgpoint"); h_hovertreeimgcontent.prepend(h_hovertreeimgcurrent.clone(true));//復(fù)制到總a集合 var h_hovertreeimgitems = h_hovertreeimgcontent.children();//所有a標(biāo)簽集合 var h_hovertreeimglength = h_hovertreeimgitems.length;//所有輪播項(xiàng)數(shù)量 var h_isswitch = true;//是否輪播 var h_circleWidth = parseInt(settings.h_circleWidth); //加邊框與間隔 var h_circleFrameWidth = (h_circleWidth + 4) * h_hovertreeimglength+2; h_hovertreeimgpoint.css({ "height": (h_circleWidth + 4), "position": "absolute", "bottom": "0px", "display": "inline-block" }) //設(shè)置圓點(diǎn)位置 switch (settings.h_circlePosition) { case 'right': h_hovertreeimgpoint.css({ "right": "0px" }) break; case 'left': h_hovertreeimgpoint.css({ "left": "0px" }) break; default: h_hovertreeimgpoint.css({ "left": "0px", "right": "0px", "width": h_circleFrameWidth + "px", "margin": "0px auto" }) break; } //切換索引 var h_hovertreeimgindex = 1; if (h_hovertreeimglength < 2) h_hovertreeimgindex = 0; //構(gòu)造圓點(diǎn) for (var h_i = 0; h_i < h_hovertreeimglength; h_i++) { h_hovertreeimgpoint.append("<div hovertreeimgdata='" + h_i + "' id='hovertreeimgpoint" + h_i + "'></div>"); } h_pointset = h_hovertreeimgpoint.find("div");//圓點(diǎn)集合 h_pointset.css({ "background-color": settings.h_circleColor, "width": settings.h_circleWidth , "height": settings.h_circleWidth , "border": "1px solid white" , "margin-left": "2px", "display": "inline-block", "border-radius": "50%" }) h_pointset.eq(0).css({ "background-color": settings.h_currentCircleColor }); //設(shè)置當(dāng)前圖片 function imgswitch(imgindex) { h_replaceFrame.html(h_hovertreeimgitems.eq(imgindex)); h_pointset.css({ "background-color": settings.h_circleColor }); h_pointset.eq(imgindex).css({ "background-color": settings.h_currentCircleColor }); } h_replaceFrame.find("img").css({ "width": settings.h_width , "height": settings.h_height }) //圓點(diǎn)操作 h_pointset.hover(function () { h_isswitch = false;//光標(biāo)懸停到圓點(diǎn)停止切換 imgswitch($(this).attr('hovertreeimgdata')); } , function () { h_isswitch = true; } ) //切換 setInterval(function () { if (!h_isswitch) return; imgswitch(h_hovertreeimgindex); h_hovertreeimgindex = (h_hovertreeimgindex + 1) % h_hovertreeimglength; }, settings.h_time) //光標(biāo)懸停到圖片停止切換 h_replaceFrame.hover(function () { h_isswitch = false; }, function () { h_isswitch = true; }) } }(jQuery));
- jQuery實(shí)現(xiàn)的3D版圖片輪播示例【滑動(dòng)輪播】
- jQuery插件slicebox實(shí)現(xiàn)3D動(dòng)畫(huà)圖片輪播切換特效
- 酷炫jQuery全屏3D焦點(diǎn)圖動(dòng)畫(huà)效果
- 基于Jquery和html5實(shí)現(xiàn)炫酷的3D焦點(diǎn)圖動(dòng)畫(huà)
- 基于jquery的圖片輪播 tab切換組件
- jQuery圖片輪播滾動(dòng)切換代碼分享
- jQuery插件Flexslider實(shí)現(xiàn)圖片輪播、圖文結(jié)合滑動(dòng)切換效果
- jquery帶有索引按鈕且自動(dòng)輪播切換特效代碼分享
- jquery實(shí)現(xiàn)左右輪播切換效果
- jQuery實(shí)現(xiàn)經(jīng)典的網(wǎng)頁(yè)3D輪播圖封裝功能【附源碼下載】
相關(guān)文章
jquery $(this).attr $(this).val方法使用介紹
$(this).attr(key); 獲取節(jié)點(diǎn)屬性名的值,相當(dāng)于getAttribute(key)方法,本文整理了一些相關(guān)的示例,感興趣的朋友可以參考下2013-10-10jquery獲取transform里的值實(shí)現(xiàn)方法
下面小編就為大家分享一篇jquery獲取transform里的值實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12Jquery刷新頁(yè)面背景圖片隨機(jī)變換的實(shí)現(xiàn)方法
Jquery刷新頁(yè)面背景圖片隨機(jī)變換的實(shí)現(xiàn)方法,需要的朋友可以參考一下2013-03-03jQuery的實(shí)現(xiàn)原理的模擬代碼 -2 數(shù)據(jù)部分
在 jQuery 中,可以對(duì)每一個(gè) DOM 對(duì)象保存私有的數(shù)據(jù)。2010-08-08jQuery中的ready函數(shù)與window.onload誰(shuí)先執(zhí)行
這篇文章主要介紹了jquery中ready函數(shù)與window.onload函數(shù)的區(qū)別,別講解了他們各自執(zhí)行的時(shí)機(jī),通俗易懂,需要的朋友可以參考下。2016-06-06Jquery 模板數(shù)據(jù)綁定插件的使用方法詳解
本篇文章是對(duì)在Jquery中模板數(shù)據(jù)綁定插件的使用方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07jQuery 打造動(dòng)態(tài)下滑菜單實(shí)現(xiàn)說(shuō)明
本教程將分步講解如何使用JQuery和CSS打造一個(gè)炫酷動(dòng)感菜單。2010-04-04基于jQuery實(shí)現(xiàn)頁(yè)面搜索功能
這篇文章主要為大家詳細(xì)介紹了基于jQuery實(shí)現(xiàn)頁(yè)面搜索功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07