jQuery插件实现带圆点的焦点图片轮播切换 - Web前端
作者:98wpeu发布时间:2026-08-15分类:网页前端技术浏览:1
导读:这次分享的代码是jQuery插件,hovertreeImg是一个图片轮播JQuery插件,使用方便,可以设置大小,圆点位置等,代码简洁<!DOCtypehtml>...
这次分享的代码是jQuery插件,hovertreeImg是一个图片轮播JQuery插件,使用方便,可以设置大小,圆点位置等,代码简洁
<!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="见缝插针" target="_blank"><img src="/themes/img/jfcz.gif" alt="见缝插针" /></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",//切换时间
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("<div id='Replaceframe'></div>");
h_replaceFrame = h_hovertreeimg.find("#replaceframe").css({ "width": "100%", "height": "100%" });
//构造圆点框
$('<div class="hovertreeimgpoint"></div>').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("<div hovertreeimgdata='" + h_i + "' id='hovertreeimgpoint" + h_i + "'></div>");
}
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 移动端artEditor富文本编辑器 - Web前端
- jQuery+css3实现转动的正方形效果(附demo源码下载) - Web前端
- jquery radio的取值_radio的选中_radio的重置方法 - Web前端
- jQuery Validate表单验证入门学习 - Web前端
- Jquery+Ajax+PHP+MySQL实现分类列表管理(下) - Web前端
- jQuery 1.9.1源码分析系列(十四)之常用jQuery工具 - Web前端
- jquery ztree实现树的搜索功能 - Web前端
- jquery实现网页的页面平滑滚动效果代码 - Web前端
- jQuery+HTML5美女瀑布流布局实现方法 - Web前端
- jQuery EasyUI实现右键菜单变灰不可用效果 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


