完美JQuery图片切换效果的简单实现


Posted in Javascript onJuly 21, 2016

效果如下:

完美JQuery图片切换效果的简单实现

css:

body { font-family:"Microsoft Yahei"; }
body,ul,li,img,h3,dl,dd,dt,h1{margin:0px;padding:0px;list-style:none;}  
img{vertical-align: top;}
/***大图切换***/
.scroll_view{margin: 0px auto;overflow:hidden;position: relative;}
.photo_view li{position:absolute;width: 100%;}
.photo_view li em,.photo_view li h3{position: absolute;bottom: 0px;z-index: 1;height: 35px;line-height: 35px;width: 100%;left: 0px;}
.photo_view li em{z-index: 1;background:rgba(0,0,0,0.5);filter: progid:DXImageTransform.Microsoft.gradient( GradientType = 0,startColorstr = '#50000000',endColorstr = '#50000000');_background:#000;}
.photo_view li h3{z-index: 2;text-indent: 1em;font-weight: normal;}
.photo_view li h3 a{color:#fff;}
.photo_view li h3 a:hover{color:#f60;}
.small_photo{position: absolute;bottom: 40px;right: 10px;cursor: pointer;z-index: 4;}
.small_photo li {float: left;padding-right: 10px;}
.small_photo li img{width: 80px;height: 35px;border: solid 2px #ccc;border-radius: 2px;}
.small_photo li.active img{border: solid 2px #f60;}

html:

<!-- start:大图切换 -->
<div class="scroll_view">
  <ul class="photo_view">
    <li><img src="images/ad1.jpg" alt="" class="" /><em></em><h3><a href="javascript:void(0);">图片效果1</a></h3></li>
    <li><img src="images/ad2.jpg" alt="" class="" /><em></em><h3><a href="javascript:void(0);">图片效果2</a></h3></li>
    <li><img src="images/ad3.jpg" alt="" class="" /><em></em><h3><a href="javascript:void(0);">图片效果3</a></h3></li>
    <li><img src="images/ad4.jpg" alt="" class="" /><em></em><h3><a href="javascript:void(0);">图片效果4</a></h3></li>
  </ul>
  <ul class="small_photo"></ul>
</div>
<!-- End:大图切换 -->

js:

$.fn.extend({  
  imgScroll:function(options){    
    var def={phtot_parent:$(".scroll_view"),photo_view:$(".photo_view"),small_photo:$(".small_photo"),speed:800,isauto:true,width:800,height:349},
      opt=$.extend({},def,options),
      $photo_view=opt.photo_view,
      $small_photo=opt.small_photo,
      speed=opt.speed,
      isauto=opt.isauto,
      index=0,
      _length=$photo_view.find("li").length,
      strTime=null;
    opt.phtot_parent.css({width:opt.width,height:opt.height});
    $photo_view.find("li:not(:first)").hide()//.find("img").hide();
    $photo_view.find("li").each(function(i){
      $small_photo.append('<li><img src="'+$(this).find("img").attr("src")+'" alt="" class="" /></li>');
    })
    $small_photo.find("li:first").addClass("active");
    //小图鼠标动作
    $small_photo.find("li").bind("mouseenter",function(){  
      clearInterval(strTime);
      if(index!=$(this).index()){
        index=$(this).index();  
        animate(index)
      }
    }).bind("mouseleave",function(){      
      if(isauto){
        start();  
      }
    });
    //大图悬停动作
    $photo_view.find("li").bind("mouseenter",function(){  
      clearInterval(strTime);      
    }).bind("mouseleave",function(){      
      if(isauto){
        start();  
      }
    });
    //自动播放
    if(isauto){
      start();  
    }
    //启动自动播放
    function start(){
      strTime=setInterval(function(){
        index >= _length-1 ? index=0 : index++;
        animate(index);
      },speed);
    }
    //动画效果
    function animate(_index){//console.log(_index)
      $small_photo.find("li").eq(_index).addClass('active').siblings().removeClass("active");//改变小图导航样式
      $photo_view.find("li").eq(_index).css("z-index",1).siblings().css("z-index",0);//控制absolute的层级
      $photo_view.find("li").eq(_index).show().find("img").css({"opacity": 0});  //装大图的opacity设置为0  
      $photo_view.find("li").eq(_index).find("img").animate({opacity:1},300,function(){
        $(this).removeAttr("style");//动画之后删除opacity
        $photo_view.find("li").eq(_index).show().siblings().hide();//显示大图  
      });//展示当前显示动画
    }
  }
});
<script type="text/javascript">
  $(function(){$("scroll_view").imgScroll({photo_view:$(".photo_view"),small_photo:$(".small_photo"),speed:3000,isauto:true}); 
  })
</script>

以上这篇完美JQuery图片切换效果的简单实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
浏览器脚本兼容 文本框中,回车键触发事件的兼容
Jun 21 Javascript
jquery多浏览器捕捉回车事件代码
Jun 22 Javascript
JavaScript实现复制功能各浏览器支持情况实测
Jul 18 Javascript
node.js中的url.format方法使用说明
Dec 10 Javascript
vue滚动轴插件better-scroll使用详解
Oct 17 Javascript
浅谈基于Vue.js的移动组件库cube-ui
Dec 20 Javascript
layui.use模块外部使用其内部定义的js封装函数方法
Sep 16 Javascript
Node.js创建一个Express服务的方法详解
Jan 06 Javascript
Vue实现简单的跑马灯
May 25 Javascript
js实现小球在页面规定的区域运动
Jun 16 Javascript
Vue清除定时器setInterval优化方案分享
Jul 21 Javascript
JS绘图Flot应用图形绘制异常解决方案
Oct 16 Javascript
jQuery的ajax下载blob文件
Jul 21 #Javascript
picLazyLoad 实现图片延时加载(包含背景图片)
Jul 21 #Javascript
浅谈DOCTYPE对$(window).height()取值的影响
Jul 21 #Javascript
jQuery新窗口打开外链接
Jul 21 #Javascript
JS for循环中i++ 和 ++i的区别介绍
Jul 20 #Javascript
javascript和jQuery实现网页实时聊天的ajax长轮询
Jul 20 #Javascript
Node.js如何自动审核团队的代码
Jul 20 #Javascript
You might like
JoshChen_php新手进阶高手不可或缺的规范介绍
2013/08/16 PHP
用PHP代替JS玩转DOM的思路及示例代码
2014/06/15 PHP
优化WordPress的Google字体以加速国内服务器上的运行
2015/11/24 PHP
thinkPHP实现递归循环栏目并按照树形结构无限极输出的方法
2016/05/19 PHP
ThinkPHP5框架实现简单的批量查询功能示例
2018/06/07 PHP
javascript中数组的concat()方法使用介绍
2013/12/18 Javascript
邮箱下拉自动填充选择示例代码附图
2014/04/03 Javascript
利用js制作html table分页示例(js实现分页)
2014/04/25 Javascript
javascript多行字符串的简单实现方式
2015/05/04 Javascript
微信小程序 购物车简单实例
2016/10/24 Javascript
jQuery Validation Engine验证控件调用外部函数验证的方法
2017/01/18 Javascript
Angular实现图片裁剪工具ngImgCrop实践
2017/08/17 Javascript
Vue SPA单页应用首屏优化实践
2018/06/28 Javascript
vue2.0中set添加属性后视图不能更新的解决办法
2019/02/22 Javascript
Vue中Table组件行内右键菜单实现方法(基于 vue + AntDesign)
2019/11/21 Javascript
js模拟实现百度搜索
2020/06/28 Javascript
javascript实现京东登录显示隐藏密码
2020/08/02 Javascript
微信小程序实现可拖动悬浮图标(包括按钮角标的实现)
2020/12/29 Javascript
vue3.0中友好使用antdv示例详解
2021/01/05 Vue.js
Nest.js散列与加密实例详解
2021/02/24 Javascript
[46:16]2018DOTA2亚洲邀请赛3月30日 小组赛B组 iG VS VP
2018/03/31 DOTA
Python 文件和输入输出小结
2013/10/09 Python
详解Python中的循环语句的用法
2015/04/09 Python
详解Python中类的定义与使用
2017/04/11 Python
python探索之BaseHTTPServer-实现Web服务器介绍
2017/10/28 Python
基于python实现在excel中读取与生成随机数写入excel中
2018/01/04 Python
Python测试人员需要掌握的知识
2018/02/08 Python
python实现简易通讯录修改版
2018/03/13 Python
Python反转序列的方法实例分析
2018/03/21 Python
基于Python生成个性二维码过程详解
2020/03/05 Python
如何在 Matplotlib 中更改绘图背景的实现
2020/11/26 Python
应用电子专业学生的自我评价
2013/10/16 职场文书
文科教师毕业的自我评价
2014/01/16 职场文书
给校长的建议书100字
2014/05/16 职场文书
合作意向书
2014/07/30 职场文书
pd.DataFrame中的几种索引变换的实现
2022/06/16 Python