;
(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. sass继承

    @extend sass中,选择器继承可以让选择器继承另一个选择器的所有样式,并联合声明.使用选择器的继承,要使用关键词@extend,后面紧跟需要继承的选择器. scss.style css.sty ...

  2. 18_CGLib动态代理

    [概述] 已知JDK动态代理中的Proxy.newProxyInstance(ClassLoader loader,Class[] interfaces,InvocationHandler h)方法的 ...

  3. 《ArcGIS Runtime SDK for Android开发笔记》——问题集:如何解决ArcGIS Runtime SDK for Android中文标注无法显示的问题(转载)

    Geodatabase中中文标注编码乱码一直是一个比较头疼的问题之前也不知道问题出在哪里?在百度后发现园子里的zssai已经对这个问题原因做了一个详细说明.这里将原文引用如下: 说明:此文转载自htt ...

  4. Angular js ng-bind 和ng-module的区别

    1.ng-bind 是从$scope ->view 的单向绑定 ,<span ng-bind="object.***"></span>只用于展示数据 ...

  5. Selenium2学习(十七)-- js处理日历控件(修改readonly属性)

    前言 日历控件是web网站上经常会遇到的一个场景,有些输入框是可以直接输入日期的,有些不能,以我们经常抢票的12306网站为例,详细讲解如何解决日历控件为readonly属性的问题. 基本思路:先用j ...

  6. python入门5 运算符

    python运算符: 1 算术运算符 加减乘除 取余 求商 求幂等 2 比较运算符==   !=  >  >=  < <= 3 逻辑运算符 and  not  or 4 赋值运 ...

  7. SQL SERVER启动时间

    select sqlserver_start_time,* from sys.dm_os_sys_info

  8. linux shell——zsh的安装与使用

    Shell是在程序员与服务器间建立一个桥梁,它对外提供一系列命令,让我们得以控制服务器.常用的Bash就是Shell的一种,也是Linux下默认Shell程序.这里介绍一种更强大的.更人性化的Shel ...

  9. SiteMesh配置下载使用(简单介绍)

    简单介绍 SiteMesh 是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的. Sitemesh是由一个基于Web页面布局.装饰以及与现存Web应用整合的框架 ...

  10. Android学习笔记_16_添加多个Activity、参数传递、请求码和结果码使用

    一.添加新的Activity步骤: 第一步:新建一个继承Activity的类,如:NewActivity public class NewActivity extends Activity { @Ov ...