jquery picswitch图片焦点图展示效果 - Web前端
作者:98wpeu发布时间:2026-06-20分类:网页前端技术浏览:54
导读:效果如下:这个插件的要点之处就在JQuery-1.4.2.JS的发布添加的新函数data的应用,所以jQuery库一定要是1.4.2的版本另一方面就是CSS的编写,SetInte...
效果如下:
这个插件的要点之处就在JQuery-1.4.2.JS的发布添加的新函数data的应用,所以jQuery库一定要是1.4.2的版本
另一方面就是CSS的编写,SetInterval和setTimeout的用法,前者是每隔多长时间执行一次,后者是多长时间执行一次;
关于settimeout的用法 有二种形式 1 settimeout(code,interval) 中的code是字符串
2 setTimeout(func,interval,args) 中的func是函数
实现代码
jquery slidepictrue *{ margin:0px; padding:0px; list-style:none; } body{ font-size:12px; color:white} #imageShow { position:relative;z-index:3;overflow:hidden;width:586px;height:150px } #imageShow #imageswitch { position:absolute;right:0px;bottom:0px;padding-left:50px;z-index:4; background-color:#C08A93;filter:Alpha(opacity=70); opacity:0.7;} #imageShow #imageSwitch li{ float:left;border-left:1px solid white;height:14px;width:30px; text-align:center;line-height:14px;} $(function(){ $imageShow=$("#imageShow"); $images=$("#imageSrc li",$imageShow); $imageSwitches=$("#imageSwitch li",$imageShow); //判断图片的张数,如果有图片 if($images.size()>0){ init(); //利用setInterval设置延迟时间,一直执行每隔1秒执行autoSwitch函数, var timer=setInterval(autoSwitch,1000); //遍历函数 $imageSwitches.each(function(index,item){ $(item).click(function(){ clearInterval(timer); // setTimeout有二种形式,第一种 setTimeout(code,interval),code是字符串,第二种 // setTimeout(func,interval,args),func是函数表达式,而不是语句 setTimeout(function(){timer=setInterval(autoSwitch,1000)},1000); $imageSwitches.css('background-color','').eq(index).css('background-color','#FF3366'); //现在用到了data函数,用于图片和下表对照 if(index!=$imageShow.data('show')){ $imageShow.data('show',index); $images.hide().eq(index).fadeIn('slow'); } }) }) } //自动显示的函数 function autoSwitch(){ $nowIndex=$imageShow.data('show')+1; if($images.size()>$nowIndex){ $imageSwitches.css('background-color','').eq($nowIndex).css('background-color','#FF3366'); $imageShow.data('show',$nowIndex); $images.hide().eq($nowIndex).fadeIn('slow'); }else{ init(); } } //初始化到第一张图片开始 function init(){ $imageShow.data('show',0); $images.hide().eq(0).fadeIn('slow'); $imageSwitches.css('background-color','').eq(0).css('background-color','#FF3366'); } });
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

这个插件的要点之处就在JQuery-1.4.2.JS的发布添加的新函数data的应用,所以jQuery库一定要是1.4.2的版本
另一方面就是CSS的编写,SetInterval和setTimeout的用法,前者是每隔多长时间执行一次,后者是多长时间执行一次;
关于settimeout的用法 有二种形式 1 settimeout(code,interval) 中的code是字符串
2 setTimeout(func,interval,args) 中的func是函数
实现代码
jquery slidepictrue *{ margin:0px; padding:0px; list-style:none; } body{ font-size:12px; color:white} #imageShow { position:relative;z-index:3;overflow:hidden;width:586px;height:150px } #imageShow #imageswitch { position:absolute;right:0px;bottom:0px;padding-left:50px;z-index:4; background-color:#C08A93;filter:Alpha(opacity=70); opacity:0.7;} #imageShow #imageSwitch li{ float:left;border-left:1px solid white;height:14px;width:30px; text-align:center;line-height:14px;} $(function(){ $imageShow=$("#imageShow"); $images=$("#imageSrc li",$imageShow); $imageSwitches=$("#imageSwitch li",$imageShow); //判断图片的张数,如果有图片 if($images.size()>0){ init(); //利用setInterval设置延迟时间,一直执行每隔1秒执行autoSwitch函数, var timer=setInterval(autoSwitch,1000); //遍历函数 $imageSwitches.each(function(index,item){ $(item).click(function(){ clearInterval(timer); // setTimeout有二种形式,第一种 setTimeout(code,interval),code是字符串,第二种 // setTimeout(func,interval,args),func是函数表达式,而不是语句 setTimeout(function(){timer=setInterval(autoSwitch,1000)},1000); $imageSwitches.css('background-color','').eq(index).css('background-color','#FF3366'); //现在用到了data函数,用于图片和下表对照 if(index!=$imageShow.data('show')){ $imageShow.data('show',index); $images.hide().eq(index).fadeIn('slow'); } }) }) } //自动显示的函数 function autoSwitch(){ $nowIndex=$imageShow.data('show')+1; if($images.size()>$nowIndex){ $imageSwitches.css('background-color','').eq($nowIndex).css('background-color','#FF3366'); $imageShow.data('show',$nowIndex); $images.hide().eq($nowIndex).fadeIn('slow'); }else{ init(); } } //初始化到第一张图片开始 function init(){ $imageShow.data('show',0); $images.hide().eq(0).fadeIn('slow'); $imageSwitches.css('background-color','').eq(0).css('background-color','#FF3366'); } });
- 1
- 2
- 3
- 4
- 5
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
相关推荐
- jquery中选择块并改变属性值的方法 - Web前端
- JQuery教学之性能优化 - Web前端
- 自定义jquery模态窗口插件无法在顶层窗口显示问题 - Web前端
- JQuery 文本框回车跳到下一个文本框示例代码 - Web前端
- jquery 按钮状态效果 正常、移上、按下 - Web前端
- jQuery中获取Radio元素值的方法 - Web前端
- jquery异步跨域访问代码 - Web前端
- 浅析JQuery获取和设置Select选项的常用方法总结 - Web前端
- Jquery显示和隐藏元素或设为只读(含Ligerui的控件禁用,实例说明介绍) - Web前端
- 浏览器打开层自动缓慢展开收缩实例代码 - Web前端
- 网页前端技术排行
-
- 1分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 2jQuery编写widget的一些技巧分享 - Web前端
- 3【第六章】Foundation之按钮和下拉功能 - Web前端
- 4[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 9javascript原生和jquery库实现iframe自适应高度和宽度 - 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属性







