;
(function ($, window, document, undefined) {

var pluginName = "scrollAnimations",
/**
* This SearchHintOptions object can be overridden during initialization
* @type {{offset: number}}
*/
defaults = {
offset: 0.8
};

var timer;

/**
* ScrollAnimations - applies an animate class to elements when scrolled into the viewport
*
* @author Westley Mon <wmarchment@mindgruve.com>
* @version 1.0.1
*
* @param {jQuery} element jQuery instance of selected elements
* @param {ScrollAnimationsOptions} options Custom options will be merged with the defaults
* @constructor
*/
function ScrollAnimations(element, options) {
if (element) {
this.element = element;
this.animationElements = [];
this.triggerPoint = null;
this.lastScrollPos = -1;

// jQuery has an extend method which merges the contents of two or
// more objects, storing the result in the first object. The first object
// is generally empty as we don't want to alter the default options for
// future instances of the plugin
this.options = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
window.onload = this.init();
}
}

ScrollAnimations.prototype = {

init: function() {
var _this = this;

var $els = $(this.element);

//setup all items
_this.setup($els);

// start an interval to update the page rather than onscroll
var scrollIntervalID = setInterval(function () {
_this.updatePage(_this);
}, 10);

$(window).on('resize', function () {
_this.resize();
});
},

resize: function () {
var _this = this;

clearTimeout(timer);

timer = setTimeout(function () {
_this.setTriggerpoint();
}, 50);
},

setTriggerpoint: function() {
this.triggerPoint = window.innerHeight * this.options.offset;
},

setup: function(items) {
this.setTriggerpoint();

var $this = $(items),
$children = $this.find('[data-animation-child]');

if ($children.length) {

// setup children
$children.each(function() {
var $child = $(this);
var $delay = $child.attr('data-animation-delay');

$child.css({
'-webkit-animation-delay': $delay,
'-moz-animation-delay': $delay,
'-ms-animation-delay': $delay,
'-o-animation-delay': $delay,
'animation-delay': $delay
});
});

} else {

var $delay = $this.attr('data-animation-delay');

// setup single item
$this.css({
'-webkit-animation-delay': $delay,
'-moz-animation-delay': $delay,
'-ms-animation-delay': $delay,
'-o-animation-delay': $delay,
'animation-delay': $delay
});

}

this.animationElements.push($this);

},

updatePage: function (plugin) {
var _this = plugin;

window.requestAnimationFrame(function () {
_this.animateElements();
});
},

animateElements: function() {
var _this = this;
var scrollPos = window.pageYOffset;

// have we scrolled since the last rAF? if not, return.
if (scrollPos === this.lastScrollPos) return;

this.lastScrollPos = scrollPos;

$(_this.animationElements).each(function() {
var $this = $(this),
$children = $this.find('[data-animation-child]');

if ($this.hasClass('animated') || (scrollPos < $this.offset().top - _this.triggerPoint))
return; // don't continue if its already been animated or scroll position hasn't hit the trigger point yet

if ($children.length) {

$this.addClass('animated');

// animate the children
$children.each(function() {
$(this).addClass('animated').addClass( $(this).attr('data-animation') )
});

} else {

// animate the single item
$this.addClass('animated').addClass( $this.attr('data-animation') );

}
});
}

};

$.fn[ pluginName ] = function (options) {
return this.each(function() {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName,
new ScrollAnimations(this, options));
}
});
};

//add support for amd
if (typeof define === "function" && define.amd) {
define(function () {
return ScrollAnimations;
});
}

})(jQuery, window, document);

jquery图片滚动jquery.scrlooAnimation.js的更多相关文章

  1. jquery图片滚动

    注:代码来自17sucai网,已去除部分冗余代码,只保留图片效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...

  2. 【精心推荐】12款很好用的 jQuery 图片滚动插件

    这里收集了12款很好用的 jQuery 图片滚动插件分享给大家.jQuery 作为最流行的 JavaScript 框架,使用简单灵活,同时还有许多优秀的插件可供使用.其中最令人印象深刻的应用之一就是各 ...

  3. 10款很好用的 jQuery 图片滚动插件

    jQuery 作为最流行的 JavaScript 框架,使用简单灵活,同时还有许多优秀的插件可供使用.其中最令人印象深刻的应用之一就是各种很酷的图片效果,它可以让的网站更具吸引力.这里收集了10款很好 ...

  4. jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动

    jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动 http://www.17sucai.com/pins/demoshow/382

  5. 求帮忙解决封装jquery图片滚动问题

    今天用jquery封装了点击图片滚动,但是发现在屏幕自适应时,图片停在的位置会随着屏幕大小而错位(我引入了pocketgrid.css响应式文件,但没办法去那边修改onsize事件...),求大神.. ...

  6. jQuery图片滚动插件

    //该组件目前仅适用于一次移动一张图片的情况 (function ($) { $.fn.extend({ "scroll": function (options) { option ...

  7. jQuery图片剪裁插件Cropper.js的使用

    插件下载地址及文档说明 1.引入必要的js和css核心文件 <link rel="stylesheet" href="../css/cropper.css" ...

  8. jquery 图片滚动

    效果图: $(function(){    $("#roll-img2").html($("#roll-img").html());    function r ...

  9. jquery图片滚动normalizy.css

    article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block; ...

随机推荐

  1. Tomcat部分操作

    一 概述 1.Tomcat是什么? Tomcat是Apache软件基金会提供的开源免费的服务器,适用于中小型系统与并发访问用户不是很多的情况. 2.域名 IP是互联网上一台计算机的唯一标识,但IP不容 ...

  2. 类数组arguments

    var isArray = function(){ return arguments; } isArray(1,2,3); // 返回[1,2,3] isArray.call(null,1,2,3); ...

  3. java应用程序已被安全设置阻止的解决办法(总有一个适合你)

    1. 在1月底的一次Java自动更新升级后,我点开已经配置好的Java小程序,赫然看到如下错误: 在网上查找了很多资料,发现就是此次更新的问题,解决方法如下: 控制面板—>Java—>安全 ...

  4. Flink -- Java Generics Programming

    Flink uses a lot of generics programming, which is an executor Framework with cluster of executor ha ...

  5. linux 中环境变量配置文件说明

    1. 修改/etc/profile文件 特点:所有用户的shell都有权使用你配置好的环境变量 说明:如果你的电脑仅用作开发,建议使用此配置,因为所有用户的shell都有权使用你配置好的环境变量,所以 ...

  6. C#操作CAD-调用winform

    个人认为用命令操作cad会比较便捷,但是鉴于好多人喜欢通过鼠标点击的方式操作cad,在此讲一下如何调用winform.前期准备请看上篇文章. 1.在新建好项目并引用接口dll的前提下,新建一个winf ...

  7. 第一次使用Git

    这次的作业是关于GIT的,一开始我并不知道GIT是啥,百度了一下才知道Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git 是 Linus Torvalds ...

  8. 一个SAP开发人员的2017总结

    今年的生活如此丰富多彩,不写一点什么怎么对得起这过去的一年? 就当记流水账,若干年之后回来看一定很有意思. 1月 有幸成为SAP Community上2位来自China的SAP mentor之一: 3 ...

  9. php多进程写入文件

    测试一 $begin = time(); for ($i=0; $i<10000; $i++) { $fp = fopen("tmp", 'r+'); fseek($fp, ...

  10. IDEA tomcat热部署方法及乱码问题解决

    在项目开发过程中,我们一般希望在修改完代码之后不重启项目即可提现出修改的结果,那么热部署项目就显得十分必要了.在idea中将项目热部署至tomcat中的方法如下: 首先打开tomcat配置界面,在se ...