首页 > 网站 > WEB开发 > 正文

jquery.BannerRotator.js

2024-04-27 15:01:17
字体:
来源:转载
供稿:网友

项目地址:https://github.com/snipertulip/BannerRotator

演示地址:http://snipertulip.github.io/BannerRotator/demo/

下载地址:https://github.com/snipertulip/BannerRotator/releases

纯js,图片动画轮播插件。

下面作为参考,具体代码,请去github.com下载,上面有链接地址。

“jquery.bannerrotator.js”插件代码:

 1 (function($, window, document, undefined) { 2     var Rotator = function(ele, opt) { 3         this.$element = ele, 4         this.defaults = { 5             "millisec": 3000 6         }, 7         this.options = $.extend({}, 8         this.defaults, opt); 9         this.last_i = 0;10         this.current_i = 0;11         this.i_count = 0;12         this.li_cache = {};13         this.li_cache_btn = {};14         this.interval = {};15         this.li_cache = this.$element.find(".animation li");16         this.li_cache_btn = this.$element.find(".button li");17         this.i_count = this.li_cache.length; (function($this) {18             $this.li_cache_btn.each(function(index, element) {19                 $(this).bind("mousedown",20                 function() {21                     if ($this.index !== $this.last_i) {22                         $this.current_i = index;23                         clearInterval($this.interval);24                         $this.action();25                         $this.interval = setInterval($this.action.bind($this), $this.options.millisec)26                     }27                 })28             })29         })(this);30         this.action();31         this.interval = setInterval(this.action.bind(this), this.options.millisec)32     };33     Rotator.PRototype = {34         action: function() {35             return (function($this) {36                 $this.li_cache.each(function(index, element) {37                     if ($this.last_i != $this.current_i && index === $this.last_i) {38                         $(element).find("[data-easing]").each(function(index, element) {39                             $(element).animate($.parseJSON(($(element).attr("data-from")).replace(//'/g, '"')), $(element).attr("data-speed"), $(element).attr("data-easing"))40                         });41                         $($this.li_cache_btn[index]).removeClass("active")42                     }43                     if (index === $this.current_i) {44                         $(element).find("[data-easing]").each(function(index, element) {45                             $(element).animate($.parseJSON(($(element).attr("data-to")).replace(//'/g, '"')), $(element).attr("data-speed"), $(element).attr("data-easing"))46                         });47                         $($this.li_cache_btn[index]).addClass("active")48                     }49                 });50                 if ($this.i_count === $this.current_i + 1) {51                     $this.last_i = $this.current_i;52                     $this.current_i = 053                 } else {54                     $this.last_i = $this.current_i++55                 }56             } (this))57         }58     };59     $.fn.html5Rotator = function(options) {60         new Rotator(this, options)61     }62 })(jQuery, window, document);
jquery.bannerrotator.js
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表