jQuery插件animateSlide制作多点滑动幻灯片


Posted in Javascript onJune 11, 2015

首页banner的酷炫效果多来自全屏大图的幻灯片动画,下面提供一种完美兼容的jquery动画特效:全新jquery多点滑动幻灯片——全屏动画animateSlide(代码完全原创)。

直接上代码,把html、css和jquery代码copy到页面上即可呈现完美画面。

html代码如下:

<div class="animateSlide">
  <div class="animateSlideImgWrap">
    <div class="animateSlideImgBox present">
      <p class="text1">亲,这是第一行标题</p>
      <p class="text2">AAAAAAAAAAAAAAAAAAAAA</p>
      <!--<img class="img" alt="" src="img/1.png" />-->
      <div class="img" style="width: 500px; height: 390px; background: #ffaeae; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 -->
    </div>
    <div class="animateSlideImgBox">
      <p class="text1">亲,这是一行宣传语</p>
      <p class="text2">BBBBBBBBBBBBBBBBBBBBB</p>
      <!--<img class="img" alt="" src="img/2.png" />-->
      <div class="img" style="width: 500px; height: 390px; background: #aeffb2; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 -->
    </div>
    <div class="animateSlideImgBox">
      <p class="text1">亲,这是一个奇迹啊</p>
      <p class="text2">CCCCCCCCCCCCCCCCCCCCC</p>
      <!--<img class="img" alt="" src="img/3.png" />-->
      <div class="img" style="width: 500px; height: 390px; background: #aebdff; opacity: 0.6;"></div><!-- 实际项目中用上面注释的半透明png图片,目前临时用div代替图片 -->
    </div>
  </div>
  <div class="animateSlideBtnL"><</div>
  <div class="animateSlideBtnR"><</div>
</div>

css代码如下:

.animateSlide {width: 100%; height: 390px; position: relative; background: #f5f5f5;}
.animateSlideImgWrap {width: 100%; height: 390px; position: absolute; z-index: 1; overflow: hidden;}
.animateSlideImgWrap .present {display: block;}
.animateSlideImgBox {width: 100%; height: 390px; position: absolute; z-index: 1; display: none;}
.animateSlideImgBox .text1 {font-family: Microsoft YaHei; font-size: 36px; line-height: 1.2em; color: #384cd0; position: absolute; top: 120px; z-index: 3; white-space: nowrap;}
.animateSlideImgBox .text2 {font-family: Microsoft YaHei; font-size: 26px; line-height: 1.2em; color: orange; position: absolute; top: 200px; z-index: 3; white-space: nowrap;}
.animateSlideImgBox .img {position: absolute; left: 470px; top: 0; z-index: 2;}
.animateSlideBtnL,
.animateSlideBtnR {
  width: 30px; height: 60px; line-height: 60px; font-size: 20px; font-weight: 700; text-align: center; background: #ddd;
  position: absolute; left: 30px; top: 150px; z-index: 6; cursor: pointer; display: none;
}
.animateSlideBtnR {left: auto; right: 20px;}

jquery代码如下:

(function($) {
  $.fn.animateSlide = function(options) {
    var defaults = {
      btnL: ".animateSlideBtnL",
      btnR: ".animateSlideBtnR",
      imgBox: ".animateSlideImgBox",
      animateTime: 500,
      delayTime: 5000,
      density: 1
    };
    var opts = $.extend(defaults, options);
    var widthWin = $(window).width();
    $(window).resize(function() {
      widthWin = $(window).width();
    });
    //
    this.on("mouseenter", function() {
      $(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeIn(400);
    }).on("mouseleave", function() {
      $(this).find(".animateSlideBtnL, .animateSlideBtnR").stop().fadeOut(400);
    });
    return this.each(function() {
      var _this = $(this);
      var _btnL = _this.find(opts.btnL);
      var _btnR = _this.find(opts.btnR);
      var _imgBox = _this.find(opts.imgBox);
      var _imgBoxCur = _imgBox.filter(".present");
      var _curText1 = _imgBoxCur.find(".text1"), _curText2 = _imgBoxCur.find(".text2"), _curImg = _imgBoxCur.find(".img");
      var _imgBoxNext = null, _nextText1 = null, _nextText2 = null, _nextImg = null;
      var index = _imgBox.index(_imgBoxCur) || 0;
      var size = _imgBox.size();
      var start = null;
      index++;
      if(index >= size) {
        index = 0;
      }
      _imgBoxNext = _imgBox.eq(index);
      _nextText1 = _imgBoxNext.find(".text1");
      _nextText2 = _imgBoxNext.find(".text2");
      _nextImg = _imgBoxNext.find(".img");
      _imgBox.find(".text1, .text2, .img").css("left", widthWin);
      _imgBoxCur.find(".text1, .text2").css("left", (widthWin - 980) / 2 + "px");
      _imgBoxCur.find(".img").css("left", (widthWin - 980) / 2 + 470 + "px");
      _btnR.on("click", function() {
        animateSlideFn();
      });
      _btnL.on("click", function() {
        animateSlideFn();
      });
      start = setTimeout(function() {
        animateSlideFn();
        start = setTimeout(arguments.callee, opts.delayTime);
      }, opts.delayTime);
      function animateSlideFn() {
        if(!(_imgBoxCur.find(".text1, .text2, .img").is(":animated") || _imgBoxNext.find(".text1, .text2, .img").is(":animated"))) {
          //当前帧动画
          _curText1.animate({
            left: parseInt(_curText1.css("left")) + 100
          }, opts.animateTime * 0.6, function() {
            _curText1.animate({
              left: "-510px"
            }, opts.animateTime);
          });
          setTimeout(function() {
            _curText2.animate({
              left: parseInt(_curText2.css("left")) + 100
            }, opts.animateTime * 0.6, function() {
              _curText2.animate({
                left: "-510px"
              }, opts.animateTime);
            });
          }, 200);
          setTimeout(function() {
            _curImg.animate({
              left: parseInt(_curImg.css("left")) + 200
            }, opts.animateTime * 0.6, function() {
              _curImg.animate({
                left: "-510px"
              }, opts.animateTime, function() {
                _imgBox.find(".text1, .text2, .img").css("left", widthWin);
                _imgBoxCur.removeClass("present");
              });
            });
          }, 400);
          //下一帧动画
          setTimeout(function() {
            _imgBoxNext.addClass("present");
            _nextText1.animate({
              left: (widthWin - 980) / 2 - 100
            }, opts.animateTime, function() {
              _nextText1.animate({
                left: (widthWin - 980) / 2
              }, opts.animateTime * 0.6);
            });
            setTimeout(function() {
              _nextText2.animate({
                left: (widthWin - 980) / 2 - 100
              }, opts.animateTime, function() {
                _nextText2.animate({
                  left: (widthWin - 980) / 2
                }, opts.animateTime * 0.6);
              });
            }, 200);
            setTimeout(function() {
              _nextImg.animate({
                left: (widthWin - 980) / 2 + 370
              }, opts.animateTime, function() {
                _nextImg.animate({
                  left: (widthWin - 980) / 2 + 470
                }, opts.animateTime * 0.6, function() {
                  index++;
                  if(index >= size) {
                    index = 0;
                  }
                  _imgBoxCur = _imgBox.filter(".present");
                  _imgBoxNext = _imgBox.eq(index);
                  _curText1 = _imgBoxCur.find(".text1");
                  _curText2 = _imgBoxCur.find(".text2");
                  _curImg = _imgBoxCur.find(".img");
                  _nextText1 = _imgBoxNext.find(".text1");
                  _nextText2 = _imgBoxNext.find(".text2");
                  _nextImg = _imgBoxNext.find(".img");
                });
              });
            }, 400);
          }, opts.density * 1200);
        }
      }
    });
  };
})(jQuery);

$(function() {
  $(".animateSlide").animateSlide({
    btnL: ".animateSlideBtnL",
    btnR: ".animateSlideBtnR",
    imgBox: ".animateSlideImgBox",
    animateTime: 500,
    delayTime: 6000,
    density: 0.9
  });
});
Javascript 相关文章推荐
Extjs学习笔记之四 工具栏和菜单
Jan 07 Javascript
replace()方法查找字符使用示例
Oct 28 Javascript
JQuery动画animate的stop方法使用详解
May 09 Javascript
jQuery中 prop() attr()使用详解
May 19 Javascript
基于Bootstrap实现tab标签切换效果
Apr 15 Javascript
学习vue.js条件渲染
Dec 03 Javascript
javascript设计模式之中介者模式学习笔记
Feb 15 Javascript
了解VUE的render函数的使用
Jun 08 Javascript
实例详解Vue项目使用eslint + prettier规范代码风格
Aug 20 Javascript
使用JS location实现搜索框历史记录功能
Dec 23 Javascript
小程序实现简单语音聊天的示例代码
Jul 24 Javascript
antd table按表格里的日期去排序操作
Nov 17 Javascript
简介JavaScript中的setDate()方法的使用
Jun 11 #Javascript
JQuery实现样式设置、追加、移除与切换的方法
Jun 11 #Javascript
在JavaScript中操作时间之getYear()方法的使用教程
Jun 11 #Javascript
JavaScript中getUTCSeconds()方法的使用详解
Jun 11 #Javascript
JQuery节点元素属性操作方法
Jun 11 #Javascript
JQuery包裹DOM节点的方法
Jun 11 #Javascript
JQuery替换DOM节点的方法
Jun 11 #Javascript
You might like
phpstorm配置Xdebug进行调试PHP教程
2014/12/01 PHP
php的debug相关函数用法示例
2016/07/11 PHP
golang与PHP输出excel示例
2016/07/22 PHP
php使用flock阻塞写入文件和非阻塞写入文件的实例讲解
2017/07/10 PHP
javascript常用代码段搜集
2014/12/04 Javascript
JavaScript实现同一页面内两个表单互相传值的方法
2015/08/12 Javascript
基于BootStrap Metronic开发框架经验小结【四】Bootstrap图标的提取和利用
2016/05/12 Javascript
javascript中Date对象的使用总结
2016/11/21 Javascript
原生js实现日期计算器功能
2017/02/17 Javascript
浅谈Node.js轻量级Web框架Express4.x使用指南
2017/05/03 Javascript
各种选择框jQuery的选中方法(实例讲解)
2017/06/27 jQuery
JS实现瀑布流布局
2017/10/21 Javascript
node.js多个异步过程中判断执行是否完成的解决方案
2017/12/10 Javascript
详解Vue实战指南之依赖注入(provide/inject)
2018/11/13 Javascript
jQuery操作cookie的示例代码
2019/06/05 jQuery
react 生命周期实例分析
2020/05/18 Javascript
numpy 计算两个数组重复程度的方法
2018/11/07 Python
python3使用matplotlib绘制散点图
2019/03/19 Python
pymysql模块的使用(增删改查)详解
2019/09/09 Python
python3获取文件中url内容并下载代码实例
2019/12/27 Python
关于pytorch处理类别不平衡的问题
2019/12/31 Python
Python爬虫实现百度翻译功能过程详解
2020/05/29 Python
python中if及if-else如何使用
2020/06/02 Python
英国豪华真皮和布艺沙发销售网站:Darlings of Chelsea
2018/01/05 全球购物
迷你唐卡软皮鞋:Minnetonka Moccasin
2018/05/01 全球购物
eDreams葡萄牙:全球最大的在线旅行社之一
2019/04/15 全球购物
英国在线定做百叶窗网站:Make My Blinds
2020/08/17 全球购物
酒吧员工的岗位职责
2013/11/26 职场文书
会计自荐书
2013/12/02 职场文书
应届本科生推荐信范文
2013/12/25 职场文书
家长会演讲稿
2014/04/26 职场文书
乡镇干部个人对照检查材料思想汇报(原创篇)
2014/09/28 职场文书
乡镇党的群众路线教育实践活动制度建设计划
2014/11/03 职场文书
2014年单位工作总结范文
2014/11/27 职场文书
2015年商场工作总结
2015/04/27 职场文书
辞职信格式范文
2015/05/13 职场文书