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

 更新时间:2016年07月21日 09:28:25   投稿:jingxian  
下面小编就为大家带来一篇完美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图片切换效果的简单实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • jquery+php随机生成红包金额数量代码分享

    jquery+php随机生成红包金额数量代码分享

    这篇文章主要介绍了jquery+php随机生成红包金额数量实现代码,红包数量与金钱可以自己设定,很实用的代码,推荐给大家,有需要的小伙伴可以参考下。
    2015-08-08
  • bootstrap table 服务器端分页例子分享

    bootstrap table 服务器端分页例子分享

    这篇文章主要介绍了bootstrap table 服务器端分页例子分享,需要的朋友可以参考下
    2015-02-02
  • 通过$(this)使用jQuery包装后的方法或属性

    通过$(this)使用jQuery包装后的方法或属性

    如果你要使用html元素本身的属性或方法就需要使用this,如果你要使用jQuery包装后的方法或属性就要$(this)
    2014-05-05
  • jQuery实现简单登录条件判断

    jQuery实现简单登录条件判断

    这篇文章主要为大家详细介绍了jQuery实现简单登录条件判断,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03
  • 自写的一个jQuery圆角插件

    自写的一个jQuery圆角插件

    下面介绍自己写的一个jQuery圆角的插件,功能非常简单。目前只能实现1px的固定弧度的圆角矩形边框。
    2010-10-10
  • jQuery EasyUI开发技巧总结

    jQuery EasyUI开发技巧总结

    这篇文章主要介绍了jQuery EasyUI开发技巧总结的相关资料,希望通过本文大家能够掌握EasyUI的开发技巧,需要的朋友可以参考下
    2017-09-09
  • jquery html动态生成select标签出问题的解决方法

    jquery html动态生成select标签出问题的解决方法

    用jquery,json从后台获取一个列表,然后用一个动态生成的select标签显示出来,结果出现错误,下面为大家分享个不错的解决方法,喜欢的朋友可以参考下
    2013-11-11
  • 基于jQuery实现的无刷新表格分页实例

    基于jQuery实现的无刷新表格分页实例

    这篇文章主要介绍了基于jQuery实现的无刷新表格分页方法,结合完整实例形式较为详细的分析了jQuery实现无刷新表格分页的具体步骤与相关实现代码,需要的朋友可以参考下
    2016-02-02
  • struts2+jquery+json实现异步加载数据(自写)

    struts2+jquery+json实现异步加载数据(自写)

    异步加载数据利用struts2+jquery+json实现,具体代码如下,感兴趣的各位可以参考下哈,希望对大家有所帮助
    2013-06-06
  • jQuery结合CSS制作漂亮的select下拉菜单

    jQuery结合CSS制作漂亮的select下拉菜单

    对于我来说,标准的HTML元素(Select)已经让我感到讨厌。它不能够正常的在IE浏览器上显示。还有一点就是他并不仅仅包含简单的文本。本实例将完全摒弃select元素,通过JQuery和CSS来构建DropDown元素。
    2015-05-05

最新评论