jquery实现的带缩略图的焦点图片切换(自动播放/响应鼠标动作)
2023-06-13 09:14:44 时间
demo04.html
复制代码代码如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>手动滚动图片</title>
<styletype="text/css">
ul,li{margin:0;padding:0}
img{border:0px;}
#container{padding:40px;}
#showAreaimg{width:700px;}
a{text-decoration:none;border:0px;}
#scrollDiv{border:#ccc1pxsolid;}
#scrollDivli{background:#A83;}
</style>
<scriptsrc="../jquery-1.8.0.min.js"type="text/javascript"></script>
<scriptsrc="manualScroll-0.1.4.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(document).ready(function(){
$.manualScroll({
objId:"scrollDiv",
showArea:"showArea",
showTitle:true,
height:105,
width:140,
line:5,
speed:1000
});
});
</script>
</head>
<body>
<divid="container">
<divid="showArea"></div>
<divid="scrollDiv">
<ul>
<li><ahref="#"><imgsrc="images/1.jpg"alt="images/1.jpg"width="140"/></a></li>
<li><ahref="#"><imgsrc="images/2.jpg"alt="images/2.jpg"width="140"/></a></li>
<li><ahref="#"><imgsrc="images/3.jpg"alt="images/3.jpg"width="140"/></a></li>
<li><ahref="#"><imgsrc="images/4.jpg"alt="images/4.jpg"width="140"/></a></li>
<li><ahref="#"><imgsrc="images/5.jpg"alt="images/5.jpg"width="140"/></a></li>
<li><ahref="#"><imgsrc="images/6.jpg"alt="images/6.jpg"width="140"/></a></li>
</ul>
</div>
</div>
</body>
</html>
manualScroll-0.1.4.js
/**
*手动滚动图片
*
**/
$.extend({
manualScroll:function(opt,callback){
//alert("suc");
this.defaults={
objId:"",//滚动区域id
showArea:"",//大图显示区域id,如果没有就不显示
showWidth:700,//大图宽度
showHeight:525,//大图高度
showTitle:false,//是否在大图下方显示标题
width:300,//每行的宽度
height:100,//div的高度
line:2,//每次滚动的行数
autoLine:1,//自动滚动的行数
speed:0,//动作时间
interval:3000,//滚动间隔
imgPath:"",//图片根目录
directBtn:"img/direct_btn02.png",//指向图片
picTimer:0,//间隔句柄,不需要设置,只是作为标识使用
opacity:0.3//按钮透明度
};
//参数初始化
varopts=$.extend(this.defaults,opt);
//定义外层元素样式
$("#"+opts.objId).css({
"position":"relative",
"overflow":"hidden",
"width":(opts.line*opts.width)+"px"
});
//定义ul样式
$("#"+opts.objId+"ul").css({
"width":opts.width*$("#"+opts.objId+"ul").find("li").size()+"px",
"height":opts.height+"px"
});
//定义li样式
$("#"+opts.objId+"ulli").css({
"display":"block",
"float":"left",
"width":opts.width+"px",
"height":opts.height+"px"
});
//添加向左滚动按钮
$("#"+opts.objId).append("<divid=\"button_left\"></div>");
//定义向左按钮的位置
$("#button_left").css({
"width":"40px",
"height":"40px",
"background":"url("+opts.imgPath+opts.directBtn+")",
"background-position":"0px0px",
"position":"absolute",
"left":"0px",
"top":(opts.height/2-20)+"px"
});
//添加向右滚动按钮
$("#"+opts.objId).append("<divid=\"button_right\"></div>");
//定义向右按钮的位置
$("#button_right").css({
"width":"40px",
"height":"40px",
"background":"url("+opts.imgPath+opts.directBtn+")",
"background-position":"-40px0px",
"position":"absolute",
"left":(opts.line*opts.width-40)+"px",
"top":(opts.height/2-20)+"px"
});
//向左按钮添加动作
$("#button_left").click(function(){
varscrollWidth=0-opts.line*opts.width-(0-$("#"+opts.objId).find("ul:first").css("margin-left").replace("px",""));
//无间断滚动
$("#"+opts.objId).find("ul:first").animate({
marginLeft:scrollWidth
},opts.speed,function(){
for(i=1;i<=opts.line;i++){
$("#"+opts.objId).find("li:first").appendTo($("#"+opts.objId).find("ul:first"));
}
$("#"+opts.objId).find("ul:first").css({marginLeft:0});
showArea();
});
});
//向右按钮添加动作
$("#button_right").click(function(){
varscrollWidth=(0-opts.line*opts.width+(0-$("#"+opts.objId).find("ul:first").css("margin-left").replace("px","")));
//无间断滚动
$("#"+opts.objId).find("ul:first").animate({
marginLeft:scrollWidth
},0,function(){
for(i=1;i<=opts.line;i++){
$("#"+opts.objId).find("li:last").prependTo($("#"+opts.objId).find("ul:first"));
}
$("#"+opts.objId).find("ul:first").animate({
marginLeft:0
},opts.speed,function(){
$("#"+opts.objId).find("ul:first").css({marginLeft:0});
showArea();
});
});
});
/**
*自动横向滚动
*/
functionscrollLeft(){
varscrollWidth=0-opts.autoLine*opts.width-(0-$("#"+opts.objId).find("ul:first").css("margin-left").replace("px",""));
$("#"+opts.objId).find("ul:first").animate({
marginLeft:scrollWidth
},opts.speed,function(){
for(i=1;i<=opts.autoLine;i++){
$("#"+opts.objId).find("li:first").appendTo($("#"+opts.objId).find("ul:first"));
}
$("#"+opts.objId).find("ul:first").css({marginLeft:0});
showArea();
});
};
/**
*大图下方显示标题
*/
if(opts.showTitle&&$("#"+opts.showArea).size()>0){
$("#"+opts.showArea).css({
"width":opts.showWidth+"px",
"position":"relative",
"height":opts.showHeight+"px"
});
$("#"+opts.showArea).html("<img/>");
$("#"+opts.showArea).append("<divid=\"manualScroll_banner\"></div>");
$("#manualScroll_banner").css({
"width":opts.showWidth+"px",
"height":"20px",
"background":"#333",
"position":"absolute",
opacity:0.7,
"text-align":"center",
"color":"#FFF",
"left":"0px",
"top":(opts.showHeight-20)+"px"
});
}
/**
*在指定区域显示大图
*/
functionshowArea(){
if($("#"+opts.showArea).size()>0){
//显示主图的位置
varindex=Math.floor((opts.line-1)/2);
showIndexArea(index);
//鼠标划上后显示大图
$("#"+opts.objId+"ulli").each(function(index){
$(this).mouseover(function(){
showIndexArea(index);
});
});
}
}
/**
*显示指定元素的大图
*/
functionshowIndexArea(index){
varimgSrc=$("#"+opts.objId+"ulli:eq("+index+")img:first").attr("src");
varimgAlt=$("#"+opts.objId+"ulli:eq("+index+")img:first").attr("alt");
//淡化显示其余图片
$("#"+opts.objId+"ulli:lt("+index+")").css({
opacity:0.5
});
$("#"+opts.objId+"ulli:gt("+index+")").css({
opacity:0.5
});
$("#"+opts.objId+"ulli:eq("+index+")").css({
opacity:1
});
//显示大图
$("#"+opts.showArea+"img:first").attr("src",imgSrc);
//显示标题
if(opts.showTitle){
$("#manualScroll_banner").text(imgAlt);
}
}
/**
*鼠标滑上后显示按钮
*/
$("#"+opts.objId).hover(function(){
$("#button_left").css({
opacity:1
});
$("#button_right").css({
opacity:1
});
},function(){
$("#button_left").css({
opacity:opts.opacity
});
$("#button_right").css({
opacity:opts.opacity
});
}).trigger("mouseleave");
/**
*最先执行的函数
*鼠标滑上焦点图时停止自动播放,滑出时开始自动播放
*/
//初始化大图
showArea();
$("#"+opts.objId).hover(function(){
clearInterval(opts.picTimer);
},function(){
opts.picTimer=setInterval(function(){
scrollLeft();
},opts.interval);//自动播放的间隔,单位:毫秒
}).trigger("mouseleave");
}
});
相关文章
- JQuery安装与下载教程(efficiency)
- jquery选择器用法_jQuery属性选择器
- 用于创建树形部件的 jQuery 插件:jsTree
- 生成二维码的 jQuery 插件:jquery.qrcode.js
- jquery 获取浏览器窗口的可视区域高度 宽度 滚动条高详解编程语言
- jQuery实现的进度条效果详解编程语言
- jQuery延迟加载(懒加载)插件 – jquery.lazyload.js详解编程语言
- jquery遍历详解编程语言
- jQuery delay()方法的用法
- jQuery技巧大放送学习jquery的朋友可以看下
- jQuery的Ajax时无响应数据的解决方法
- jQuery选择没有colspan属性的td的代码
- jQuery学习笔记之jQuery的DOM操作
- Jquery知识点三jquery表单对象操作
- jQuery控制输入框只能输入数值的小例子
- jQuery学习笔记(3)--用jquery(插件)实现多选项卡功能
- jQuery学习笔记(4)--Jquery中获取table中某列值的具体思路
- jQuery弹出(alert)select选择的值
- jquery实现智能感知连接外网搜索
- UpdatePanel和jQuery不兼容局部刷新jquery失效
- jQuery插件实现表格隔行换色且感应鼠标高亮行变色
- Jquery实现的tab效果可以指定默认显示第几页
- jquery的live使用注意事项
- jQuery操作表格(table)的常用方法、技巧汇总
- jQuery实现响应浏览器缩放大小并改变背景颜色
- 基于jquery固定于顶部的导航响应浏览器滚动条事件
- 一款基jquery超炫的动画导航菜单可响应单击事件
- 分享2个jQuery插件--jquery.fileupload与artdialog
- jQuery实现ichat在线客服插件
- Jquery响应回车键直接提交表单操作代码