标签:android style blog http io ar os 使用 sp
/** * @param {Object|String} 需要改变css属性最终状态值或者是注册动画 * @param {Object} 动画基本配置,可以查看默认配置 */ $element.velocity(properties, options)
/** * @param {Object} 操作元素,可以是原生对象,也可以是包装对象 * @param {Object|String} 需要改变css属性最终状态值或者是注册动画 * @param {Object} 动画基本配置,可以查看默认配置 */ $.Velocity($element, properties, options);
$.Velocity.RegisterEffect(name, { defaultDuration: duration, calls: [ [ { property: value }, durationPercentage, { options } ], [ { property: value }, durationPercentage, { options } ] ], reset: { property: value, property: value } });
$.Velocity.RegisterEffect("callout.pulse", { defaultDuration: 900, calls: [ [ { scaleX: 1.1 }, 0.50 ], [ { scaleX: 1 }, 0.50 ] ] });
callout.bounce,callout.shake,callout.flash,callout.pulse,callout.swing,callout.tada,transition.fadeIn,transition.fadeOut,transition.flipXIn,transition.flipXOut,transition.flipYIn,transition.flipYOut,transition.flipBounceXIn,transition.flipBounceXOut,transition.flipBounceYIn,transition.flipBounceYOut,transition.swoopIn,transition.swoopOut,transition.whirlIn,transition.whirlOut,transition.shrinkIn,transition.shrinkOut,transition.expandIn,transition.expandOut,transition.bounceIn,transition.bounceOut,transition.bounceUpIn,transition.bounceUpOut,transition.bounceDownIn,transition.bounceDownOut,transition.bounceLeftIn,transition.bounceLeftOut,transition.bounceRightIn,transition.bounceRightOut,transition.slideUpIn,transition.slideUpOut,transition.slideDownIn,transition.slideDownOut,transition.slideLeftIn,transition.slideLeftOut,transition.slideRightIn,transition.slideRightOut,transition.slideUpBigIn,transition.slideUpBigOut,transition.slideDownBigIn,transition.slideDownBigOut,transition.slideLeftBigIn,transition.slideLeftBigOut,transition.slideRightBigIn,transition.slideRightBigOut,transition.perspectiveUpIn,transition.perspectiveUpOut,transition.perspectiveDownIn,transition.perspectiveDownOut,transition.perspectiveLeftIn,transition.perspectiveLeftOut,transition.perspectiveRightIn,transition.perspectiveRightOut
var mySequence = [ { elements: $element1, properties: { translateX: 100 }, options: { duration: 1000 } }, { elements: $element2, properties: { translateX: 200 }, options: { duration: 1000, sequenceQueue: false }, { elements: $element3, properties: { translateX: 300 }, options: { duration: 1000?} ]; $.Velocity.RunSequence(mySequence); //默认队列动画是按照顺序执行的,可以通过设置sequenceQueue改变当前元素执行时机。默认是true,当为true时,指的是按照顺序执行,如果设置成false指的是,可以和上一个元素动画同时执行
$element.velocity(properties, options).then(); //需要注意是的是无线循环和队列不支持该形式
/** * 动画处理 * author: 黑MAO */ $(function() { ‘use strict‘; /****内部方法开始****/ /** * css动画执行函数 * @param {Object} 目标元素 * @param {String} 初始class * @param {String} 动画类型 * @param {Number} 动画时长 * @param {Number} 动画延迟 * @param {Number} 循环次数 */ var timer; function _cssRun(targetEl, className, animation, duration, delay, loop) { duration = duration*1 || 1000; delay = delay*1 || 0; loop = (loop || loop == 0) ? loop*1 : 1; if(loop < 1) { loop = ‘infinite‘; } $(targetEl).removeClass(); $(targetEl).addClass(className).addClass(animation); $(targetEl).css({ ‘animation-duration‘: duration+‘ms‘, ‘animation-delay‘: delay+‘ms‘, ‘animation-iteration-count‘: loop+‘‘ }); if(loop != ‘infinite‘) { clearTimeout(timer); timer = setTimeout(function() { $(targetEl).removeClass(animation); }, duration*loop + delay); } } /** * 监听select变化方法 * @param {Object} 目标元素 * @param {Object} 操作元素集合 * @param {String} 初始class * @param {String} 动画类型 ["css", "js"] */ function _changeFunc(targetEl, opElementObj, className, animationType) { var animation = $(opElementObj.animationEl).val(); var duration = $(opElementObj.durationEl).val(); var delay = $(opElementObj.delayEl).val(); var loop = $(opElementObj.loopEl).val(); if(animationType == "css") { _cssRun(targetEl, className, animation, duration, delay, loop); }else { var ras = new Ras(); if(animation) { ras.run(targetEl, ‘stop‘); ras.run(targetEl, animation, {duration: duration, delay: delay, stagger: 200, drag: true}); } } } /** * 初始化动画 * @param {Array} 动画数组 * @param {Object} 操作元素对象 * @param {Object} 目标元素 * @param {Number} 动画延迟 * @param {String} 需要显示的动画类型 ["show", "hide", "normal", "all"] * @param {String} 动画类型 ["css", "js"] */ function _initAnimation(animationArr, opElementObj, targetEl, type, animationType) { var conf = opElementObj; var className = $(targetEl).attr("class"); $(conf.animationEl).prepend(‘<option value="" diabled="disabled">选择动画类型</option>‘); $(animationArr).each(function(key, val) { var isShow = false; switch(type) { case "show": if(val.indexOf(‘In‘) > 0) { isShow = true; } break; case "hide": if(val.indexOf(‘Out‘) > 0) { isShow = true; } break; case "normal": if(val.indexOf(‘Out‘) == -1 && val.indexOf(‘In‘) == -1) { isShow = true; } break; default: isShow = true; break; } isShow && $(conf.animationEl).append(‘<option value="‘+val+‘">‘+val+‘</option>‘); }); $(conf.animationEl).on(‘change‘, function() { _changeFunc(targetEl, conf, className, animationType); }); $(conf.durationEl).on(‘change‘, function() { _changeFunc(targetEl, conf, className, animationType); }); $(conf.delayEl).on(‘change‘, function() { _changeFunc(targetEl, conf, className, animationType); }); $(conf.loopEl).on(‘change‘, function() { _changeFunc(targetEl, conf, className, animationType); }); } /****内部方法结束****/ function Ras(opts) { var conf = { beforeIndex : 0, //上一页序列号 currentIndex : 0, //当前页序列号 playing : true, //是否在运行 downward : true, //是否向下滚动 imgList: [], //页面内图片列表 quenes: { show: [], //页面显示列表 hide: [] //页面隐藏列表 }, navFunc: null, //导航回调函数 cssAnimationExtra: [], //css动画扩展 jsAnimationExtra: [] //js动画扩展 }; this.conf = $.extend(conf, opts); } //对外暴漏 window.Ras = Ras; $.extend(Ras.prototype, { init: function() { var self = this; var conf = this.conf; //绑定键盘和鼠标事件 var quenes = conf.quenes; var showList = conf.quenes.show; var hideList = conf.quenes.hide; var senceNum = showList.length; $(document).on(‘mousewheel keyup‘,function(e){ if( !conf.playing ){ conf.playing = true; if( e.keyCode && (e.keyCode==39||e.keyCode==40)){ conf.downward = true; } if( e.keyCode && (e.keyCode==37||e.keyCode==38) ){ conf.downward = false; } if( e.deltaY){ conf.downward = e.deltaY<0?true:false; } if( e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40 || e.deltaY ){ conf.beforeIndex = conf.currentIndex; conf.currentIndex = conf.downward ?conf.currentIndex + 1:conf.currentIndex - 1; conf.currentIndex = conf.currentIndex>=senceNum?0:conf.currentIndex; conf.currentIndex = conf.currentIndex<0?senceNum-1:conf.currentIndex; conf.navFunc && conf.navFunc(conf.currentIndex); self.show(hideList[conf.beforeIndex], showList[conf.currentIndex], function() { conf.playing = false; }); } } return false; }); //处理图片预加载 var imgList = conf.imgList; imgList.length && self.imgLoader(imgList); //默认显示第一屏 self.show(null, showList[0], function() { conf.playing = false; }); }, /** * 初始化CSS动画 * @param {Object} 联动元素集合 * @param {Object} 目标元素 * @param {String} 选项类型 ["show", "hide", "normal", "all"] */ initCssAnimation: function(opElementObj, targetEl, type) { var conf = this.conf; var animationStr = ‘bounce,pulse,rubberBand,shake,swing,tada,bounceIn,bounceInDown,bounceInLeft,bounceInRight,bounceInUp,bounceOut,bounceOutDown,bounceOutLeft,bounceOutRight,bounceOutUp,fadeIn,fadeInDown,fadeInDownBig,fadeInLeft,fadeInLeftBig,fadeInRight,fadeInRightBig,fadeInUp,fadeInUpBig,fadeOut,fadeOutDown,fadeOutDownBig,fadeOutLeft,fadeOutLeftBig,fadeOutRight,fadeOutRightBig,fadeOutUp,fadeOutUpBig,flip,flipInX,flipInY,flipOutX,flipOutY,lightSpeedOut,rotateIn,rotateInDownLeft,rotateInDownRight,rotateInUpLeft,rotateInUpRight,rotateOut,rotateOutDownLeft,rotateOutDownRight,rotateOutUpLeft,rotateOutUpRight,hinge,rollIn,rollOut,zoomIn,zoomInDown,zoomInLeft,zoomInRight,zoomInUp,zoomOut,zoomOutDown,zoomOutLeft,zoomOutRight,zoomOutUp,slideInDown,slideInLeft,slideInRight,slideInUp,slideOutDown,slideOutLeft,slideOutRight,slideOutUp,magic,openDownLeft,openDownRight,openUpLeft,openUpRight,openDownLeftRetourn,openDownRightRetourn,openUpLeftRetourn,openUpRightRetourn,openDownLeftOut,openDownRightOut,openUpLeftOut,openUpRightOut,perspectiveDown,perspectiveLeft,perspectiveRight,perspectiveUp,perspectiveDownRetourn,perspectiveLeftRetourn,perspectiveRightRetourn,perspectiveUpRetourn,puffIn,puffOut,rotateDown,rotateLeft,rotateRight,rotateUp,slideDown,slideLeft,slideRight,slideUp,slideDownRetourn,slideLeftRetourn,slideRightRetourn,slideUpRetourn,swap,twisterInDown,twisterInUp,vanishIn,vanishOut,swashOut,swashIn,foolishOut,holeOut,tinRightOut,tinLeftOut,tinUpOut,tinDownOut,tinRightIn,tinUpIn,tinDownIn,bombRightOut,bombLeftOut,boingInUp,boingOutDown,spaceOutUp,spaceOutRight,spaceOutLeft,spaceInUp,spaceInRight,spaceInDown,spaceInLeft,boomIn,circleRotate‘; var animationArr = animationStr.split(‘,‘); var arr = []; $.merge(arr, animationArr, conf.cssAnimationExtra); arr = $.unique(arr); _initAnimation(arr, opElementObj, targetEl, type, ‘css‘); }, /** * 初始化JS动画 * @param {Object} 联动元素集合 * @param {Object} 目标元素 * @param {String} 选项类型 ["show", "hide", "normal", "all"] */ initJsAnimation: function(opElementObj, targetEl, type) { var conf = this.conf; var animationStr = ‘callout.bounce,callout.shake,callout.flash,callout.pulse,callout.swing,callout.tada,transition.fadeIn,transition.fadeOut,transition.flipXIn,transition.flipXOut,transition.flipYIn,transition.flipYOut,transition.flipBounceXIn,transition.flipBounceXOut,transition.flipBounceYIn,transition.flipBounceYOut,transition.swoopIn,transition.swoopOut,transition.whirlIn,transition.whirlOut,transition.shrinkIn,transition.shrinkOut,transition.expandIn,transition.expandOut,transition.bounceIn,transition.bounceOut,transition.bounceUpIn,transition.bounceUpOut,transition.bounceDownIn,transition.bounceDownOut,transition.bounceLeftIn,transition.bounceLeftOut,transition.bounceRightIn,transition.bounceRightOut,transition.slideUpIn,transition.slideUpOut,transition.slideDownIn,transition.slideDownOut,transition.slideLeftIn,transition.slideLeftOut,transition.slideRightIn,transition.slideRightOut,transition.slideUpBigIn,transition.slideUpBigOut,transition.slideDownBigIn,transition.slideDownBigOut,transition.slideLeftBigIn,transition.slideLeftBigOut,transition.slideRightBigIn,transition.slideRightBigOut,transition.perspectiveUpIn,transition.perspectiveUpOut,transition.perspectiveDownIn,transition.perspectiveDownOut,transition.perspectiveLeftIn,transition.perspectiveLeftOut,transition.perspectiveRightIn,transition.perspectiveRightOut‘; var animationArr = animationStr.split(‘,‘); var arr = []; $.merge(arr, animationArr, conf.cssAnimationExtra); arr = $.unique(arr); _initAnimation(arr, opElementObj, targetEl, type, ‘js‘); }, /** * 入场动画 * @param {Array} 出场队列 * @param {Array} 入场队列 * @param {Function} 入场完成回调 */ show: function(beforeQuene, currentQuene, callback) { var self = this; self.hide(beforeQuene); currentQuene && self.run(currentQuene).then(function() { callback && callback(); }); }, /** * 出场动画 * @param {Array} 出场队列 * @param {Function} 出场完成回调 */ hide: function(quene, callback) { var self = this; callback && callback(); quene && self.run(quene); }, /** * 图片懒加载 * @param {Array} 图片列表 * @param {Function} 图片加载回调 */ imgLoader: function(imgList, callback) { var count = imgList.length, i = 0, success = 0, failed = 0, failList = []; for ( ; i < count ; i++ ) { var img = new Image(); (function(i){ img.onload = function () { success++; if( (success + failed) == count ) { callback&&callback.call( imgList , failed, failList); } }; img.onerror = function () { failed++; failList.push(imgList[i]); if( (success + failed) == count ) { callback&&callback.call( imgList , failed, failList ); } }; img.src = imgList[i]; })(i); } }, /** * 注册自定义动画 */ register: function() { var self = this; var args = [].slice.apply(arguments); $.Velocity.RegisterEffect.apply(self, args); }, /** * 封装velocity方法,统一管理队列和单个动画 * @return {Object} promise对象 */ run: function() { var deferred = $.Deferred(); var self = this; var args = [].slice.call(arguments); var len = args[0].length; if($.isArray(args[0])) { if(!args[0][len-1].options){ args[0][len-1].options = {}; } args[0][len-1].options.complete = function() { deferred.resolve(); }; $.Velocity.RunSequence.call(self, args[0]); return deferred.promise(); }else { return $.Velocity.animate.apply(self, args); } }, /** * 启动CSS动画 * @param {Object} 操作元素 * @param {String} 初始class * @param {String} css动画 * @param {Number} 动画时长 * @param {Number} 动画延迟 * @return {Object} promise对象 */ cssAnimationRun: function(targetEl, className, animation, duration, delay, loop) { loop = (loop === true) ? 0 : loop; _cssRun(targetEl, className, animation, duration, delay, loop); }, /** * 启动JS动画 * @param {Object} 操作元素 * @param {String} css动画 * @param {Number} 动画时长 * @param {Number} 动画延迟 * @return {Object} promise对象 */ jsAnimationRun: function(targetEl, animation, options) { var opts = { stagger: 200, drag: true }; opts = $.extend(opts, options); if(animation) { this.run(targetEl, ‘stop‘); this.run(targetEl, animation, opts); } } }); });
var ras = new Ras({ cssAnimationExtra: [‘bounce‘], jsAnimationExtra: [‘callout.bounce‘] }); ras.init(); //调用相关方法
<script src="http://s3.qhimg.com/!44713922/bluebird.js" ></script>
<script src="http://s6.qhimg.com/!7c8590ec/jquery.mousewheel.min.js"></script>
<script src="http://s3.qhimg.com/!20821230/velocity.min.js"></script>
<script src="http://s5.qhimg.com/!d0b08d4d/velocity.ui.min.js"></script>
标签:android style blog http io ar os 使用 sp
原文地址:http://www.cnblogs.com/xiaoheimiaoer/p/4162546.html