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; ...
随机推荐
- 【数据库】6.0 MySQL入门学习(六)——MySQL启动与停止、官方手册、文档查询
1.0 MySQL主要有四种启动方式:直接启动.安全启动.服务启动.多实例启动. 直接启动: 服务器启动: 安全启动(最常用): 多实例启动: 2.0如何获得MySQL帮助 2.1官方手册 下面提供百 ...
- H5跟ios、android交互跟数据对接
需求: APP要用H5页面做展示,而且要获取到对应的商品ID,用户点击H5页面跳回APP原生页面. 方法: 先要判断用户是ios还是android设备(这里只考虑ios跟android,因为它俩写法还 ...
- 通知:即日起本博客暂停更新,请移步至yanxin8.com获取最新文章
通知:即日起本博客暂停更新,请移步至yanxin8.com与博主交流及获取最新文章
- 【IOS】IOS综合
取精华.去糟粕!适合iOS开发者的15大网站推荐 E:/IOS视频: IOS基础/01 苹果开发零基础教程 3780m --> 63h /02 IOS开发快速入门教程 /03 IOS开发进阶教 ...
- Siebel escript学习笔记
Siebel(escript)的学习:1.Siebel的数据类型Primitive(原始的)---Number,Integer,Hexadecimal(十六进制),Octal(八进制),Floatin ...
- 设计模式之装饰模式(Decorator)
1. 装饰者模式,动态地将责任附加到对象上.若要扩展功能,装饰者提供了比继承更加有弹性的替代方案. 2.组合和继承的区别 继承.继承是给一个类添加行为的比较有效的途径.通过使用继承,可以使得子类在拥有 ...
- 从java9开始就不再提供32位jdk
- static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
查看HashMap源码,发现这个static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; 值为16. 这个是位移算法. 例如: 4<& ...
- 自动驾驶self driving知识点mark
C++, algorithm, RTOS,TX2, CAN, 标准, car model,
- Git 版本管理器学习笔记
难点:使用 git revert <commit_id> 操作实现以退为进, git revert 不同于 git reset 它不会擦除"回退"之后的 commit_ ...