0

0

jQuery插件实现带圆点的焦点图片轮播切换_jquery

php中文网

php中文网

发布时间:2016-05-16 15:19:26

|

1509人浏览过

|

来源于php中文网

原创

这次分享的代码是jquery插件,hovertreeimg是一个图片轮播jquery插件,使用方便,可以设置大小,圆点位置等,代码简洁





  
  
  


  
  


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",//切换时间
      h_borderColor: "transparent",//边框颜色
      h_width: "500",//宽度
      h_height: "200",//高度
      h_circleWidth: "18",//方框边长
      h_circleColor:"silver",//圆点颜色
      h_currentCircleColor: "red",//当前圆点颜色
      h_circlePosition:"right"//圆点位置
    }, 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("
"); h_replaceFrame = h_hovertreeimg.find("#replaceframe").css({ "width": "100%", "height": "100%" }); //构造圆点框 $('
').appendTo(h_hovertreeimg); var h_hovertreeimgpoint = h_hovertreeimg.find(".hovertreeimgpoint"); h_hovertreeimgcontent.prepend(h_hovertreeimgcurrent.clone(true));//复制到总a集合 var h_hovertreeimgitems = h_hovertreeimgcontent.children();//所有a标签集合 var h_hovertreeimglength = h_hovertreeimgitems.length;//所有轮播项数量 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" }) //设置圆点位置 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; //构造圆点 for (var h_i = 0; h_i < h_hovertreeimglength; h_i++) { h_hovertreeimgpoint.append("
"); } h_pointset = h_hovertreeimgpoint.find("div");//圆点集合 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 }); //设置当前图片 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 }) //圆点操作 h_pointset.hover(function () { h_isswitch = false;//光标悬停到圆点停止切换 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) //光标悬停到图片停止切换 h_replaceFrame.hover(function () { h_isswitch = false; }, function () { h_isswitch = true; }) } }(jQuery));

多种切换效果之jQuery焦点图片轮播插件
多种切换效果之jQuery焦点图片轮播插件

多种切换效果之jQuery焦点图片轮播插件

下载
Img插件EasySector插件见缝插针

相关专题

更多
c++主流开发框架汇总
c++主流开发框架汇总

本专题整合了c++开发框架推荐,阅读专题下面的文章了解更多详细内容。

26

2026.01.09

c++框架学习教程汇总
c++框架学习教程汇总

本专题整合了c++框架学习教程汇总,阅读专题下面的文章了解更多详细内容。

24

2026.01.09

学python好用的网站推荐
学python好用的网站推荐

本专题整合了python学习教程汇总,阅读专题下面的文章了解更多详细内容。

72

2026.01.09

学python网站汇总
学python网站汇总

本专题整合了学python网站汇总,阅读专题下面的文章了解更多详细内容。

9

2026.01.09

python学习网站
python学习网站

本专题整合了python学习相关推荐汇总,阅读专题下面的文章了解更多详细内容。

10

2026.01.09

俄罗斯手机浏览器地址汇总
俄罗斯手机浏览器地址汇总

汇总俄罗斯Yandex手机浏览器官方网址入口,涵盖国际版与俄语版,适配移动端访问,一键直达搜索、地图、新闻等核心服务。

52

2026.01.09

漫蛙稳定版地址大全
漫蛙稳定版地址大全

漫蛙稳定版地址大全汇总最新可用入口,包含漫蛙manwa漫画防走失官网链接,确保用户随时畅读海量正版漫画资源,建议收藏备用,避免因域名变动无法访问。

183

2026.01.09

php学习网站大全
php学习网站大全

精选多个优质PHP入门学习网站,涵盖教程、实战与文档,适合零基础到进阶开发者,助你高效掌握PHP编程。

12

2026.01.09

php网站搭建教程大全
php网站搭建教程大全

本合集专为零基础用户打造,涵盖PHP网站搭建全流程,从环境配置到实战开发,免费、易懂、系统化,助你快速入门建站!

8

2026.01.09

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
jQuery 教程
jQuery 教程

共42课时 | 4万人学习

HTML+CSS基础与实战
HTML+CSS基础与实战

共132课时 | 9.4万人学习

tp6+adminlte搭建通用后台
tp6+adminlte搭建通用后台

共39课时 | 5.7万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

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