WoW.js插件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WoW.js插件相关的知识,希望对你有一定的参考价值。
时间:2017.11.02----2017.11.04
author: gaoxuerong
先上效果图点击这里
这是我在看WoW.js源码的时候写的,自己也是不理解,所以是边看,边百度,把自己查的资料整理下,由于本人能力有限,不能很好的讲解,就只是粗略的写了下,
开始总体看起来是(function(){}).call(this)讲解详见https://segmentfault.com/q/1010000002519489
- 其实[].indexOf和
- function(item) {
- for (var i = 0, l = this.length; i < l; i++) {
- if (i in this && this[i] === item)
- return i;
- }return -1;
- };的作用是一样的;你懂得;
- Util = (function() {return Util;})()//立即执行函数
- function Util() {}
- Util.prototype.extend = function(custom, defaults) {
- var key, value;
- for (key in defaults) {
- value = defaults[key];
- if (custom[key] == null) {
- custom[key] = value;
- }
- }
- return custom;
- };
- WeakMap=this.WeakMap || this.MozWeakMap || (WeakMap = (function() {return WeakMap;})())
- function WeakMap() {
- this.keys = [];
- this.values = [];
- }
- 然后在WeakMap原型上扩展了get set方法;
- WeakMap.prototype.get(key)返回key关联对象, 或者 undefined(没有key关联对象时)。WeakMap.prototype.set(key, value)在WeakMap中设置一组key关联对象,返回这个 WeakMap对象。关于WeakMap详见http://es6.ruanyifeng.com/#docs/set-map
- MutationObserver =(MutationObserver = (function() {
- function MutationObserver() {}
- return MutationObserver;
- getComputedStyle = this.getComputedStyle || function(el, pseudo) {
- return this;
- }
- Window.getComputedStyle() 方法给出应用活动样式表后的元素的所有CSS属性的值,并解析这些值可能包含的任何基本计算。关于getComputedStyle详见https://developer.mozilla.org/zh-CN/docs/Web/API/Window/getComputedStyle
- this.WOW = (function() {
- return WOW;
- })()
- WOW.prototype.defaults = {
- boxClass: ‘wow‘,
- animateClass: ‘animated‘,
- offset: 0,
- mobile: true,//手机是否支持
- live: true,
- callback: null,
- scrollContainer: null
- };
- function WOW(options) {
- if (options == null) {
- options = {};
- }
- this.scrollCallback = bind(this.scrollCallback, this);
- this.scrollHandler = bind(this.scrollHandler, this);
- this.resetAnimation = bind(this.resetAnimation, this);
- this.start = bind(this.start, this);
- this.scrolled = true;
- this.config = this.util().extend(options, this.defaults);
- if (options.scrollContainer != null) {
- this.config.scrollContainer = document.querySelector(options.scrollContainer);
- }
- this.animationNameCache = new WeakMap();
- this.wowEvent = this.util().createEvent(this.config.boxClass);
- }
- 然后在Wow.prototype上扩展了方法init[初始化]; start ;stop ;sync[同步] ;doSync; show;applyStyle;animate;resetStyle;resetAnimation;customStyle;vendorSet;vendorCSS;animationName;cacheAnimationName;cachedAnimationName;scrollHandler;scrollCallback;offsetTop;isVisible;util;disabled;
WoW.js基本用法
具体动画效果,详见animate.css
具体css3动画效果详见:http://css.doyoe.com/
自己可以根据animate.css源码分析,只要了解css3动画的用法就好;
例如:1. fadeInDown
在animate.css中有:
透明度从opacity:0到opacity:1;在外轴上平移:从-20px到0;
2.bounceInDown
3.rollIn
4.lightSpeedIn
5.bounceInRight
6.flipInX
7.shake
8.swing
9.bounceInUp
10.pulse
11.bounce
12.flip
- @keyframes flip {
- 0% {
- -webkit-transform: perspective(400px) translateZ(0) rotateY(0) scale(1);
- -ms-transform: perspective(400px) translateZ(0) rotateY(0) scale(1);
- transform: perspective(400px) translateZ(0) rotateY(0) scale(1);
- -webkit-animation-timing-function: ease-out;
- animation-timing-function: ease-out;
- }
- 40% {
- -webkit-transform: perspective(400px) translateZ(150px) rotateY(170deg) scale(1);
- -ms-transform: perspective(400px) translateZ(150px) rotateY(170deg) scale(1);
- transform: perspective(400px) translateZ(150px) rotateY(170deg) scale(1);
- -webkit-animation-timing-function: ease-out;
- animation-timing-function: ease-out;
- }
- 50% {
- -webkit-transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1);
- -ms-transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1);
- transform: perspective(400px) translateZ(150px) rotateY(190deg) scale(1);
- -webkit-animation-timing-function: ease-in;
- animation-timing-function: ease-in;
- }
- 80% {
- -webkit-transform: perspective(400px) translateZ(0) rotateY(360deg) scale(.95);
- -ms-transform: perspective(400px) translateZ(0) rotateY(360deg) scale(.95);
- transform: perspective(400px) translateZ(0) rotateY(360deg) scale(.95);
- -webkit-animation-timing-function: ease-in;
- animation-timing-function: ease-in;
- }
- 100% {
- -webkit-transform: perspective(400px) translateZ(0) rotateY(360deg) scale(1);
- -ms-transform: perspective(400px) translateZ(0) rotateY(360deg) scale(1);
- transform: perspective(400px) translateZ(0) rotateY(360deg) scale(1);
- -webkit-animation-timing-function: ease-in;
- animation-timing-function: ease-in;
- }
- }
13.tada
- @keyframes tada {
- 0% {
- -webkit-transform: scale(1);
- -ms-transform: scale(1);
- transform: scale(1);
- }
- 10%, 20% {
- -webkit-transform: scale(0.9) rotate(-3deg);
- -ms-transform: scale(0.9) rotate(-3deg);
- transform: scale(0.9) rotate(-3deg);
- }
- 30%, 50%, 70%, 90% {
- -webkit-transform: scale(1.1) rotate(3deg);
- -ms-transform: scale(1.1) rotate(3deg);
- transform: scale(1.1) rotate(3deg);
- }
- 40%, 60%, 80% {
- -webkit-transform: scale(1.1) rotate(-3deg);
- -ms-transform: scale(1.1) rotate(-3deg);
- transform: scale(1.1) rotate(-3deg);
- }
- 100% {
- -webkit-transform: scale(1) rotate(0);
- -ms-transform: scale(1) rotate(0);
- transform: scale(1) rotate(0);
- }
- }
以上是关于WoW.js插件的主要内容,如果未能解决你的问题,请参考以下文章