jquery图片滚动jquery.scrlooAnimation.js
;
(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的更多相关文章
- jquery图片滚动
注:代码来自17sucai网,已去除部分冗余代码,只保留图片效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...
- 【精心推荐】12款很好用的 jQuery 图片滚动插件
这里收集了12款很好用的 jQuery 图片滚动插件分享给大家.jQuery 作为最流行的 JavaScript 框架,使用简单灵活,同时还有许多优秀的插件可供使用.其中最令人印象深刻的应用之一就是各 ...
- 10款很好用的 jQuery 图片滚动插件
jQuery 作为最流行的 JavaScript 框架,使用简单灵活,同时还有许多优秀的插件可供使用.其中最令人印象深刻的应用之一就是各种很酷的图片效果,它可以让的网站更具吸引力.这里收集了10款很好 ...
- jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动
jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动 http://www.17sucai.com/pins/demoshow/382
- 求帮忙解决封装jquery图片滚动问题
今天用jquery封装了点击图片滚动,但是发现在屏幕自适应时,图片停在的位置会随着屏幕大小而错位(我引入了pocketgrid.css响应式文件,但没办法去那边修改onsize事件...),求大神.. ...
- jQuery图片滚动插件
//该组件目前仅适用于一次移动一张图片的情况 (function ($) { $.fn.extend({ "scroll": function (options) { option ...
- jQuery图片剪裁插件Cropper.js的使用
插件下载地址及文档说明 1.引入必要的js和css核心文件 <link rel="stylesheet" href="../css/cropper.css" ...
- jquery 图片滚动
效果图: $(function(){ $("#roll-img2").html($("#roll-img").html()); function r ...
- jquery图片滚动normalizy.css
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block; ...
随机推荐
- Lucene 初识
因为业务需要,虽然自己不是专门写搜索的,但是需要自己拼一些搜索条件去调用搜索的接口,而之前看的JVM crash里也涉及到了Lucene,所以大概了解一下. 参考文档: http://www.itey ...
- jsp九大内置对象==欣欣
内置对象特点: 1. 由JSP规范提供,不用编写者实例化. 2. 通过Web容器实现和管理 3. 所有JSP页面均可使用 4. ...
- Div+Css布局教程(-)CSS必备知识
目录: 1.Div+Css布局教程(-)CSS必备知识 注:本教程要求对html和css有基础了解. 一.CSS布局属性 Width:设置对象的宽度(width:45px). Height:设置对象的 ...
- Java Web 常用在线api汇总(不定时更新)
1.Hibernate API Documentation (3.2.2.ga) http://www.hibernate.org/hib_docs/v3/api/ 2.Spring Framewor ...
- check_mk通用应用检测插件
客户端mk_tvmapp import json filename = '/tmp/tvmapp.json' print '<<<tvmapp>>>' for a ...
- winform中 让 程序 自己重启
private void button1_Click(object sender, EventArgs e) { Application.ExitThread(); ...
- 将CSV文件中的数据导入到SQL Server 数据库中
导入数据时,需要注意 CSV 文件中的数据是否包含逗号以及双引号,存在时,导入会失败 选择数据库 -> 右键 -> 任务 -> 导入数据 ,然后根据弹出的导入导出向导(如下图)中的提 ...
- 【css基础】html图片右上角加上删除按钮
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 怎么看电脑有没有安装USB3.0驱动
1.首先要看主板是否带USB3.0接口. 2.然后计算机-属性-设备管理器-通用串行总线,就可以看到是否有安装USB3.0驱动
- USB3.0驱动与2.0有什么区别
安装好usb3.0驱动就可以驱动usb 3.0设备,能够适应于大部份主板,帮助用户解决usb3.0和电脑无法正常通讯的问题,并支持winxp,win7和win8系统,是目前网络上最好用的usb3.0万 ...