酷炫jQuery全屏3D焦点图动画效果


Posted in Javascript onMarch 22, 2016

这又是一款很不错的jQuery焦点图动画,它的特点是整个焦点图基本是全屏显示的,非常大气,而且图片的倾斜也给整个焦点图3D立体的视觉效果,而且焦点图的图片切换非常流畅,相当实用。

酷炫jQuery全屏3D焦点图动画效果

HTML代码:

<div class="wrapper">

</div>

<div id="pxs_container" class="pxs_container">
 <div class="pxs_bg">
 <div class="pxs_bg1"></div>
 <div class="pxs_bg2"></div>
 <div class="pxs_bg3"></div>
 </div>
 <div class="pxs_loading">Loading images...</div>
 <div class="pxs_slider_wrapper">
 <ul class="pxs_slider">
  <li><img src="images/1.jpg" alt="First Image" /></li>
  <li><img src="images/2.jpg" alt="Second Image" /></li>
  <li><img src="images/3.jpg" alt="Third Image" /></li>
  <li><img src="images/4.jpg" alt="Forth Image" /></li>
  <li><img src="images/5.jpg" alt="Fifth Image" /></li>
  <li><img src="images/6.jpg" alt="Sixth Image" /></li>
 </ul>
 <div class="pxs_navigation">
  <span class="pxs_next"></span>
  <span class="pxs_prev"></span>
 </div>
 <ul class="pxs_thumbnails">
  <li><img src="images/thumbs/1.jpg" alt="First Image" /></li>
  <li><img src="images/thumbs/2.jpg" alt="Second Image" /></li>
  <li><img src="images/thumbs/3.jpg" alt="Third Image" /></li>
  <li><img src="images/thumbs/4.jpg" alt="Forth Image" /></li>
  <li><img src="images/thumbs/5.jpg" alt="Fifth Image" /></li>
  <li><img src="images/thumbs/6.jpg" alt="Sixth Image" /></li>
 </ul>
 </div>
</div>

JavaScript代码

(function($) {
 $.fn.parallaxSlider = function(options) {
 var opts = $.extend({}, $.fn.parallaxSlider.defaults, options);
 return this.each(function() {
  var $pxs_container = $(this),
  o   = $.meta ? $.extend({}, opts, $pxs_container.data()) : opts;

  //the main slider
  var $pxs_slider = $('.pxs_slider',$pxs_container),
  //the elements in the slider
  $elems  = $pxs_slider.children(),
  //total number of elements
  total_elems = $elems.length,
  //the navigation buttons
  $pxs_next = $('.pxs_next',$pxs_container),
  $pxs_prev = $('.pxs_prev',$pxs_container),
  //the bg images
  $pxs_bg1 = $('.pxs_bg1',$pxs_container),
  $pxs_bg2 = $('.pxs_bg2',$pxs_container),
  $pxs_bg3 = $('.pxs_bg3',$pxs_container),
  //current image
  current  = 0,
  //the thumbs container
  $pxs_thumbnails = $('.pxs_thumbnails',$pxs_container),
  //the thumbs
  $thumbs  = $pxs_thumbnails.children(),
  //the interval for the autoplay mode
  slideshow,
  //the loading image
  $pxs_loading = $('.pxs_loading',$pxs_container),
  $pxs_slider_wrapper = $('.pxs_slider_wrapper',$pxs_container);

  //first preload all the images
  var loaded = 0,
  $images = $pxs_slider_wrapper.find('img');

  $images.each(function(){
  var $img = $(this);
  $('<img/>').load(function(){
   ++loaded;
   if(loaded == total_elems*2){
   $pxs_loading.hide();
   $pxs_slider_wrapper.show();

   //one images width (assuming all images have the same sizes)
   var one_image_w = $pxs_slider.find('img:first').width();

   /*
   need to set width of the slider,
   of each one of its elements, and of the
   navigation buttons
    */
   setWidths($pxs_slider,
   $elems,
   total_elems,
   $pxs_bg1,
   $pxs_bg2,
   $pxs_bg3,
   one_image_w,
   $pxs_next,
   $pxs_prev);

   /*
    set the width of the thumbs
    and spread them evenly
    */
   $pxs_thumbnails.css({
    'width'  : one_image_w + 'px',
    'margin-left' : -one_image_w/2 + 'px'
   });
   var spaces = one_image_w/(total_elems+1);
   $thumbs.each(function(i){
    var $this = $(this);
    var left = spaces*(i+1) - $this.width()/2;
    $this.css('left',left+'px');

    if(o.thumbRotation){
    var angle = Math.floor(Math.random()*41)-20;
    $this.css({
     '-moz-transform' : 'rotate('+ angle +'deg)',
     '-webkit-transform' : 'rotate('+ angle +'deg)',
     'transform'  : 'rotate('+ angle +'deg)'
    });
    }
    //hovering the thumbs animates them up and down
    $this.bind('mouseenter',function(){
    $(this).stop().animate({top:'-10px'},100);
    }).bind('mouseleave',function(){
    $(this).stop().animate({top:'0px'},100);
    });
   });

   //make the first thumb be selected
   highlight($thumbs.eq(0));

   //slide when clicking the navigation buttons
   $pxs_next.bind('click',function(){
    ++current;
    if(current >= total_elems)
    if(o.circular)
     current = 0;
    else{
    --current;
    return false;
    }
    highlight($thumbs.eq(current));
    slide(current,
    $pxs_slider,
    $pxs_bg3,
    $pxs_bg2,
    $pxs_bg1,
    o.speed,
    o.easing,
    o.easingBg);
   });
   $pxs_prev.bind('click',function(){
    --current;
    if(current < 0)
    if(o.circular)
     current = total_elems - 1;
    else{
    ++current;
    return false;
    }
    highlight($thumbs.eq(current));
    slide(current,
    $pxs_slider,
    $pxs_bg3,
    $pxs_bg2,
    $pxs_bg1,
    o.speed,
    o.easing,
    o.easingBg);
   });

   /*
   clicking a thumb will slide to the respective image
    */
   $thumbs.bind('click',function(){
    var $thumb = $(this);
    highlight($thumb);
    //if autoplay interrupt when user clicks
    if(o.auto)
    clearInterval(slideshow);
    current = $thumb.index();
    slide(current,
    $pxs_slider,
    $pxs_bg3,
    $pxs_bg2,
    $pxs_bg1,
    o.speed,
    o.easing,
    o.easingBg);
   });

   /*
   activate the autoplay mode if
   that option was specified
    */
   if(o.auto != 0){
    o.circular = true;
    slideshow = setInterval(function(){
    $pxs_next.trigger('click');
    },o.auto);
   }

   /*
   when resizing the window,
   we need to recalculate the widths of the
   slider elements, based on the new windows width.
   we need to slide again to the current one,
   since the left of the slider is no longer correct
    */
   $(window).resize(function(){
    w_w = $(window).width();
    setWidths($pxs_slider,$elems,total_elems,$pxs_bg1,$pxs_bg2,$pxs_bg3,one_image_w,$pxs_next,$pxs_prev);
    slide(current,
    $pxs_slider,
    $pxs_bg3,
    $pxs_bg2,
    $pxs_bg1,
    1,
    o.easing,
    o.easingBg);
   });

   }
  }).error(function(){
   alert('here')
  }).attr('src',$img.attr('src'));
  });

 });
 };

 //the current windows width
 var w_w  = $(window).width();

 var slide  = function(current,
 $pxs_slider,
 $pxs_bg3,
 $pxs_bg2,
 $pxs_bg1,
 speed,
 easing,
 easingBg){
 var slide_to = parseInt(-w_w * current);
 $pxs_slider.stop().animate({
  left : slide_to + 'px'
 },speed, easing);
 $pxs_bg3.stop().animate({
  left : slide_to/2 + 'px'
 },speed, easingBg);
 $pxs_bg2.stop().animate({
  left : slide_to/4 + 'px'
 },speed, easingBg);
 $pxs_bg1.stop().animate({
  left : slide_to/8 + 'px'
 },speed, easingBg);
 }

 var highlight = function($elem){
 $elem.siblings().removeClass('selected');
 $elem.addClass('selected');
 }

 var setWidths = function($pxs_slider,
 $elems,
 total_elems,
 $pxs_bg1,
 $pxs_bg2,
 $pxs_bg3,
 one_image_w,
 $pxs_next,
 $pxs_prev){
 /*
 the width of the slider is the windows width
 times the total number of elements in the slider
  */
 var pxs_slider_w = w_w * total_elems;
 $pxs_slider.width(pxs_slider_w + 'px');
 //each element will have a width = windows width
 $elems.width(w_w + 'px');
 /*
 we also set the width of each bg image div.
 The value is the same calculated for the pxs_slider
  */
 $pxs_bg1.width(pxs_slider_w + 'px');
 $pxs_bg2.width(pxs_slider_w + 'px');
 $pxs_bg3.width(pxs_slider_w + 'px');

 /*
 both the right and left of the
 navigation next and previous buttons will be:
 windowWidth/2 - imgWidth/2 + some margin (not to touch the image borders)
  */
 var position_nav = w_w/2 - one_image_w/2 + 3;
 $pxs_next.css('right', position_nav + 'px');
 $pxs_prev.css('left', position_nav + 'px');
 }

 $.fn.parallaxSlider.defaults = {
 auto  : 0, //how many seconds to periodically slide the content.
    //If set to 0 then autoplay is turned off.
 speed  : 1000,//speed of each slide animation
 easing  : 'jswing',//easing effect for the slide animation
 easingBg : 'jswing',//easing effect for the background animation
 circular : true,//circular slider
 thumbRotation : true//the thumbs will be randomly rotated
 };
 //easeInOutExpo,easeInBack
})(jQuery);

调用插件的JavaScript代码

$(function() {
 var $pxs_container = $('#pxs_container');
 $pxs_container.parallaxSlider();
});

以上就是本文的全部内容,希望对大家学习jquery程序设计有所帮助。

Javascript 相关文章推荐
jQuery 选择器、DOM操作、事件、动画
Nov 25 Javascript
jQuery中bind,live,delegate与one方法的用法及区别解析
Dec 30 Javascript
js 数组操作之pop,push,unshift,splice,shift
Jan 29 Javascript
jQuery基于当前元素进行下一步的遍历
May 20 Javascript
JavaScript实现下拉菜单的显示和隐藏
Jan 05 Javascript
axios 处理 302 状态码的解决方法
Apr 10 Javascript
React中如何引入Angular组件详解
Aug 09 Javascript
详解Node.js中path模块的resolve()和join()方法的区别
Oct 29 Javascript
this在vue和小程序中的使用详解
Jan 28 Javascript
vue + typescript + 极验登录验证的实现方法
Jun 27 Javascript
vue设置导航栏、侧边栏为公共页面的例子
Nov 01 Javascript
vue 中url 链接左边的小图标更改问题
Dec 30 Javascript
浅析C/C++,Java,PHP,JavaScript,Json数组、对象赋值时最后一个元素后面是否可以带逗号
Mar 22 #Javascript
使用struts2+Ajax+jquery验证用户名是否已被注册
Mar 22 #Javascript
使用getBoundingClientRect方法实现简洁的sticky组件的方法
Mar 22 #Javascript
Node.js文件操作方法汇总
Mar 22 #Javascript
浅谈Sticky组件的改进实现
Mar 22 #Javascript
使用Sticky组件实现带sticky效果的tab导航和滚动导航的方法
Mar 22 #Javascript
关于JS中match() 和 exec() 返回值和属性的测试
Mar 21 #Javascript
You might like
php获取url字符串截取路径的文件名和扩展名的函数
2010/01/22 PHP
采用PHP函数memory_get_usage获取PHP内存清耗量的方法
2011/12/06 PHP
使用正则替换变量
2007/05/05 Javascript
Ext JS Grid在IE6 下宽度的问题解决方法
2009/02/15 Javascript
编写自己的jQuery插件简单实现代码
2011/04/19 Javascript
JS中引用百度地图并将百度地图的logo和信息去掉
2013/09/29 Javascript
解决extjs grid 不随窗口大小自适应的改变问题
2014/01/26 Javascript
JavaScript onkeypress事件入门实例(按下或按住一个键盘按键)
2014/10/17 Javascript
基于jQuery实现的图片切换焦点图整理
2014/12/07 Javascript
JavaScript中匿名函数用法实例
2015/03/23 Javascript
js实现右键自定义菜单
2016/12/03 Javascript
微信小程序学习(4)-系统配置app.json详解
2017/01/12 Javascript
基于Angular.js实现的触摸滑动动画实例代码
2017/02/19 Javascript
关于angular浏览器兼容性问题的解决方案
2020/07/26 Javascript
python list使用示例 list中找连续的数字
2014/01/27 Python
python使用socket远程连接错误处理方法
2015/04/29 Python
详解Python中的各种函数的使用
2015/05/24 Python
Python网络爬虫出现乱码问题的解决方法
2017/01/05 Python
python实现简单flappy bird
2018/12/24 Python
实例介绍Python中整型
2019/02/11 Python
python实现切割url得到域名、协议、主机名等各个字段的例子
2019/07/25 Python
python爬虫 urllib模块发起post请求过程解析
2019/08/20 Python
python实现两个字典合并,两个list合并
2019/12/02 Python
Pytorch中的VGG实现修改最后一层FC
2020/01/15 Python
Python图像处理库PIL中图像格式转换的实现
2020/02/26 Python
在keras里面实现计算f1-score的代码
2020/06/15 Python
使用python爬取抖音app视频的实例代码
2020/12/01 Python
女子锻炼服装和瑜伽服装:Splits59
2019/03/04 全球购物
本科生学习总结的自我评价
2013/10/02 职场文书
财政专业求职信范文
2014/02/19 职场文书
2014年党支部学习材料
2014/05/19 职场文书
个人批评与自我批评发言稿
2014/09/28 职场文书
大学军训决心书
2015/02/05 职场文书
大学毕业生个人总结
2015/02/28 职场文书
幼儿园见习总结
2015/06/23 职场文书
Java字符串逆序方法详情
2022/03/21 Java/Android