0

0

jquery实现的带缩略图的焦点图片切换(自动播放/响应鼠标动作)_jquery

php中文网

php中文网

发布时间:2016-05-16 17:43:07

|

1423人浏览过

|

来源于php中文网

原创

demo04.html
复制代码 代码如下:





手动滚动图片










  • images/1.jpg

  • images/2.jpg

  • images/3.jpg

  • images/4.jpg

  • images/5.jpg

  • images/6.jpg







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 // 按钮透明度
};

//参数初始化
var opts = $.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 + " ul li").css({
"display":"block",
"float":"left",
"width":opts.width + "px",
"height":opts.height + "px"
});

// 添加向左滚动按钮
$("#"+opts.objId).append("
");

// 定义向左按钮的位置
$("#button_left").css({
"width":"40px",
"height":"40px",
"background":"url(" + opts.imgPath + opts.directBtn + ")",
"background-position":"0px 0px",
"position":"absolute",
"left":"0px",
"top":(opts.height/2 - 20) + "px"
});

// 添加向右滚动按钮
$("#"+opts.objId).append("
");

// 定义向右按钮的位置
$("#button_right").css({
"width":"40px",
"height":"40px",
"background":"url(" + opts.imgPath + opts.directBtn + ")",
"background-position":"-40px 0px",
"position":"absolute",
"left":(opts.line * opts.width - 40) + "px",
"top":(opts.height/2 - 20) + "px"
});

// 向左按钮添加动作
$("#button_left").click(function(){
var scrollWidth = 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.objId).find("li:first").appendTo($("#"+opts.objId).find("ul:first"));
}
$("#"+opts.objId).find("ul:first").css({marginLeft:0});
showArea();
});
});

// 向右按钮添加动作
$("#button_right").click(function(){
var scrollWidth = (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.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();
});
});
});

/**
* 自动横向滚动
*/
function scrollLeft(){
var scrollWidth = 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.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("jquery实现的带缩略图的焦点图片切换(自动播放/响应鼠标动作)_jquery");
$("#"+opts.showArea).append("
");
$("#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"
});
}

/**
* 在指定区域显示大图
*/
function showArea(){
if($("#"+opts.showArea).size() > 0){
// 显示主图的位置
var index = Math.floor((opts.line - 1) / 2);
showIndexArea(index);
// 鼠标划上后显示大图
$("#"+opts.objId + " ul li").each(function(index){
$(this).mouseover(function(){
showIndexArea(index);
});
});
}
}

/**
* 显示指定元素的大图
*/
function showIndexArea(index){
var imgSrc = $("#"+opts.objId + " ul li:eq(" + index + ") img:first").attr("src");
var imgAlt = $("#"+opts.objId + " ul li:eq(" + index + ") img:first").attr("alt");
// 淡化显示其余图片
$("#"+opts.objId + " ul li:lt(" + index + ")").css({
opacity:0.5
});
$("#"+opts.objId + " ul li:gt(" + index + ")").css({
opacity:0.5
});
$("#"+opts.objId + " ul li: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");
}
});

相关专题

更多
Word 字间距调整方法汇总
Word 字间距调整方法汇总

本专题整合了Word字间距调整方法,阅读下面的文章了解更详细操作。

2

2025.12.24

任务管理器教程
任务管理器教程

本专题整合了任务管理器相关教程,阅读下面的文章了解更多详细操作。

2

2025.12.24

AppleID格式
AppleID格式

本专题整合了AppleID相关内容,阅读专题下面的文章了解更多详细教程。

0

2025.12.24

csgo视频观看入口合集
csgo视频观看入口合集

本专题整合了csgo观看入口合集,阅读下面的文章了知道更多入口地址。

29

2025.12.24

yandex外贸入口合集
yandex外贸入口合集

本专题汇总了yandex外贸入口地址,阅读下面的文章了解更多内容。

58

2025.12.24

添加脚注通用方法
添加脚注通用方法

本专题整合了添加脚注方法合集,阅读专题下面的文章了解更多内容。

1

2025.12.24

重启电脑教程汇总
重启电脑教程汇总

本专题整合了重启电脑操作教程,阅读下面的文章了解更多详细教程。

3

2025.12.24

纸张尺寸汇总
纸张尺寸汇总

本专题整合了纸张尺寸相关内容,阅读专题下面的文章了解更多内容。

5

2025.12.24

Java Spring Boot 微服务实战
Java Spring Boot 微服务实战

本专题深入讲解 Java Spring Boot 在微服务架构中的应用,内容涵盖服务注册与发现、REST API开发、配置中心、负载均衡、熔断与限流、日志与监控。通过实际项目案例(如电商订单系统),帮助开发者掌握 从单体应用迁移到高可用微服务系统的完整流程与实战能力。

1

2025.12.24

热门下载

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

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PHP水印与缩略图最新视频教程
PHP水印与缩略图最新视频教程

共10课时 | 1.7万人学习

PHP开发水印与缩略图教程
PHP开发水印与缩略图教程

共10课时 | 4.2万人学习

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

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