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; ...
随机推荐
- Python基础 数据类型 (字符串、列表、字典、元组、集合、堆、栈、树)
数据类型有整型.布尔.字符串.列表.字典.元组.集合.堆.栈和树. 1.整型: 整型就是数字 数字表示 python2 64位机器,范围-2^63~2^63-1 超出上述范围,python自动转化为l ...
- 让zepto支持ie
找到zepto源码:修改为如下代码: zepto.Z = function(dom, selector) { dom = dom || [] // 支持ie10,主要是支持wp8 if(window. ...
- Linux下的环境部署和项目发布
1.查看系统版本 sudo uname --m i686 //表示是32位 x86_64 // 表示是64位 2.下载对应版本软件,jdk和Tomcat(切记注意版本) jdk: 下载地址:http: ...
- ahp层次分析法软件
http://www.jz5u.com/Soft/trade/Other/58808.html 权重计算 归一化 本组当前数 - 本组最小 / 本组最大-本组最小 http://blog.csdn.n ...
- koa2获取用户ip
调用下面方法即可获取 // koa2 中 req 为 ctx.req const getUserIp = (req) => { return req.headers['x-forwarded-f ...
- java maven项目 导入jar包注意
1.将jar 包放到lib目录下 2.build path 3.点击maven主项目右键选择properties 4.选择myeclipse 下的第一个选项 5.点击add 选择archives ...
- 【Leetcode】【Easy】Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note:You may assume tha ...
- Docker 容器中相关软件安装
Docker 容器中相关软件安装 1.介绍 我们从docker hub下载的centos镜像是只有很少的命令,需要单独安装我们所需的相关软件. 2.安装软件 安装yum-utils软件包 该软件包是辅 ...
- JUnit报错:java.lang.ClassNotFoundException: com.mogodb.test.test
最近在使用JUnit做单元测试时,发现新写好的测试类运行总是出错,报找不到类异常. Class not found com.mogodb.test.test java.lang.ClassNotFou ...
- selenium:IE浏览器获取cookie提示Could not retrieve cookies
from selenium import webdriver url = "https://www.baidu.com" dr = webdriver.Ie() dr.get(ur ...