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; ...
随机推荐
- C#工具类之数据库连接
一.SQL Server /// <summary> /// 数据库的通用访问代码 /// 此类为抽象类, /// 不允许实例化,在应用时直接调用即可 /// </summary&g ...
- 使用canvas及js简单生成验证码方法
在很多时候都需要用到验证码,前端验证码需要知道Html5中的canvas知识点.验证码生成步骤是:1.生成一张画布canvas 2.生成随机数验证码 3.在画布中生成干扰线 4.把验证码文本填充到 ...
- SharePoint 2013 - Breadcrumb
By default SharePoint 2013 doesn’t have a breadcrumb (like the 2010 version used to have). This was ...
- Recsys2018 music recomendation
http://www.recsyschallenge.com/2018/ January 2018 Release of the "One Million Playlists" d ...
- 去掉iframe白色背景方法
在iframe内添加如下代码 style="display:none" onload="this.style.display = 'block';" 先让它不显 ...
- Azure 8月众多新版本公布
Azure 8月新发布:IoT 中心S3 版,Azure 热/冷存储层,DocumentDB,SQL Server Stretch Database, MySQL 5.7, Cloud Foundry ...
- BeginInvoke和EndInvoke方法
本系列教程主要包括如下内容:1. BeginInvoke和EndInvoke方法 2. Thread类 3. 线程池 4. 线程同步基础 5. 死锁 6. 线程同步的7种方法 7. 如何在线程中访问G ...
- Python——追加学习笔记(三)
错误与异常 AttributeError:尝试访问未知的对象属性 eg. >>> class myClass(object): ... pass ... >>> m ...
- mysql:删除表数据drop、truncate和delete的用法
程度从强到弱 1.drop table tb drop将表格直接删除,没有办法找回 2.truncate (table) tb 删除表中的所有数据,不能与where一起使用 ...
- Kubernetes stateful set讲解以及一个基于postgreSQL的具体例子
Stateful Set是Kubernetes 1.9版本新引入的一个概念,用于管理有状态的应用. Kubernetes官方文档: https://kubernetes.io/docs/concept ...