小米note4上市时间7银色好看吗

查看: 1257|回复: 0
分享JQuery动画插件Velocity.js的六种列表加载特效
TA的每日心情衰 16:20签到天数: 6 天[LV.2]偶尔看看I
本帖最后由 yetaoaiueo 于
11:25 编辑
& && &&&Velocity.js &i&slice + sequence&/i&&/h1&
& & &pre&Only anim X number with FX#1, animate Y number with FX#2 etc / Read JS source for more
&span&v1.0 – Added code&/span&
& & &div id=&btn&&
& && &&&&i class=&type1&&Run type 1&/i& &i class=&type2&&Type 2&/i& &i class=&type3&&Type 3&/i&
& && &&&&i class=&type4&&Type 4&/i& &i class=&type5&&Type 5&/i& &i class=&type6&&Type 6&/i&&/div&
& & &div id=&boxes&&
& && &&&&!-- load via JSONP --&
& & &/div&
& & &!-- /#boxes --&
& & &script src='jquery.js'&&/script&
& & &script src='velocity.min.js'&&/script&
& & &script src='velocity.ui.min.js'&&/script&
& & &script&/*
&&+ jquery.js
&&+ velocity.js
&&+ velocity.ui.js
/* -----------------------------------------------------
VELOCITY.JS SLUCE + SEQUENCE
Animate different boxes with different animations and sequence it.
This demo has a bounch of stuff not needed for a basic slice + sequence
since everything is wrapped up in a function and lots of if/else statements.
For basic usage of using Velocity sequence go to:
----------------------------------------------------- */
// Define base div
var boxes = $('#boxes');
/* -----------------------------------------------------
REGISTER CLICK EVENTS FOR BUTTONS
----------------------------------------------------- */
$('.type1').click(function(){
&&goVelocity(true);
$('.type2').click(function(){
&&goVelocity(true, 'custom.flickDownIn', 'custom.flickUpIn', vOption2);
$('.type3').click(function(){
&&goVelocity(true, 'custom.zoomOutIn', 'custom.zoomInIn', vOption3);
$('.type4').click(function(){
&&goVelocity(true, 'custom.superZoomOutIn', 'custom.superZoomOutIn', vOption4);
$('.type5').click(function(){
&&goVelocity('type5', '', '', vOption5);
$('.type6').click(function(){
&&goVelocity('type7', '', '', vOption5);
/* -----------------------------------------------------
GET SOME CONTENTS
100% UNRELATED to animation, scroll down the 'real' stuff
----------------------------------------------------- */
boxes.append('&div id=&load&&Loading data...&/div&')
var getMax = 12;
var str = '';
//var tags = 'tommiehansen+sunset';
tags = 'tommiehansen',
sort = 'interestingness-desc';
$.getJSON(uri,
&&function(data) {
& & $.each(data.value.items, function(i,item){
& &&&var img = item. img = img.replace('.jpg','_m.jpg');
& && &&&str += '&div class=&box&&';
& && &&&str += '&img src=&' + img + '& width=&240& height=&159& /&&/a&';
& && &&&str += '&div class=&boxRight&&&h3&' + item.title + '&/h3&&i&Photo &span&by&/span& ';
& && &&&str += '&/div&&/div&';
& && &if (i == getMax-1) { }
& & boxes.empty().append(str);
& & goVelocity(); // run initial
/* -----------------------------------------------------
BEGIN VELOCITY ANIMATIONS
----------------------------------------------------- */
// Register new animations
$.Velocity.RegisterUI(&custom.slideUpIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateY: [0,90], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.slideDownIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateY: [0,-90], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.slideLeftIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateX: [0,-90], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.slideRightIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateX: [0,90], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.zoomOutIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], scale:[1,1.5], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.zoomInIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], scale:[1,0.5], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.superZoomOutIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], scale:[1,5], translateZ: 0, translateY: [0,500] } ]],
$.Velocity.RegisterUI(&custom.flickUpIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateY: [0,90], rotateZ: [0,10], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.flickDownIn&, {
&&defaultDuration: 500,
&&calls: [[ { opacity: [1,0], translateY: [0,-90], rotateZ: [0,-10], translateZ: 0 } ]]
$.Velocity.RegisterUI(&custom.fadeOut&, {
&&defaultDuration: 300,
&&calls: [[ { opacity: 0, translateZ: 0 } ]],
&&reset: { translateY:0, opacity:0, rotateZ:0, scale:1, translateX:0 }
// Define some Velocity option VARs for re-use etc
var vOption = { duration: 400, stagger: 60, easing: 'easeOutQuad', display: false };
var vOption2 = { duration: 300, stagger: 90, easing: 'easeOutExpo', display: false };
var vOption3 = { duration: 300, stagger: 60, easing: 'easeOutQuad', display: false };
var vOption4 = { duration: 700, stagger: 60, easing:'easeOutQuad', display: false };
var vOption5 = { duration: 500, easing:'easeOutQuad', display: false };
var vOption6 = { duration: 500, easing:'easeOutQuad', display: false, sequenceQueue: false };
// Default transitions
anim1 = 'custom.slideLeftIn',
anim2 = 'custom.slideRightIn';
function goVelocity(isOut, ani1, ani2, vOpt) {
&&if(!ani1) { ani1 = anim1, ani2 = anim2 };
&&if(!vOpt) { vOpt = vO };
&&// base VARs
&&var box = boxes.find('.box');
&&// Slice boxes to different groups (for IN-transitions)
&&slice1 = 3, // 1-3
&&slice2 = 6, // 4-6
&&slice3 = 9; // 7-9
&&// setup Velocity sequence
&&seq1 = box.slice(0, slice1).get(),& && &&&// .get() = transform jquery object to raw DOM nodes
&&seq2 = box.slice(slice1, slice2).get(),
&&seq3 = box.slice(slice2, slice3).get(),
&&seq4 = box.slice(slice3).get();& && && & // rest of elements after slice3
&&var velocityS
&&$.Velocity(box.get(), &stop&);&&// stop all animation if one is already running
&&// Begin a lot of if()
&&if(isOut==true){
& & velocitySequence = [
& && &{ elements: box.get(), properties: 'custom.fadeOut', options: vOption },
& && &{ elements: seq1, properties: ani1, options: vOpt },
& && &{ elements: seq2, properties: ani2, options: vOpt },
& && &{ elements: seq3, properties: ani1, options: vOpt },
& && &{ elements: seq4, properties: ani2, options: vOpt }
& & $.Velocity.RunSequence(velocitySequence);
&&else if(isOut=='type5'){
& & var b = box.get(); // convert to raw dom nodes
& & var nth1 = box.filter(':nth-child(3n+1)').get();
& & var nth2 = box.filter(':nth-child(3n)').get();
& & var nth3 = box.filter(':nth-child(3n-1)').get();
& & velocitySequence = [
& && &{ elements: b, properties: 'custom.fadeOut', options: vOption },
& && &{ elements: nth1, properties: 'custom.slideDownIn', options: vOpt },
& && &{ elements: nth2, properties: 'custom.slideUpIn', options: vOption6 },
& && &{ elements: nth3, properties: 'custom.zoomOutIn', options: vOption3 },
& & $.Velocity.RunSequence(velocitySequence);
&&else if(isOut=='type6'){
& & var b = box.get(); // convert to raw dom nodes
& & var one = box.slice(0,1)
& & var two = box.slice(1,3);
& & var three = box.slice(3);
& & velocitySequence = [
& && &{ elements: b, properties: 'custom.fadeOut', options: vOption },
& && &{ elements: one, properties: 'custom.slideDownIn', options: vOpt },
& && &{ elements: two, properties: 'transition.slideUpIn', options: vOption6 },
& && &{ elements: three, properties: 'transition.slideDownIn', options: vOption5 },
& & $.Velocity.RunSequence(velocitySequence);
&&else if(isOut=='type7'){
& & var b = box.get(); // convert to raw dom nodes
& & //var s1 = box.eq(0);
& & //var s2 = box.eq(4)
& & var s0 = box.slice(0,1);
& & var s1 = box.slice(1,2);
& & var s2 = box.slice(2,3);
& & var s3 = box.filter(':nth-child(3n-1)');
& & s3 = s3.slice(1); // skip first
& & var s4 = box.filter(':nth-child(3n+1)');
& & s4 = s4.slice(1); // skip first
& & var s5 = box.filter(':nth-child(3n)');
& & s5 = s5.slice(1); // skip first
& & velocitySequence = [
& && &{ elements: b, properties: 'custom.fadeOut', options: vOption },
& && &{ elements: s0, properties: 'custom.slideLeftIn', options: vOpt },
& && &{ elements: s1, properties: 'custom.slideDownIn', options: vOption6 },
& && &{ elements: s2, properties: 'custom.slideRightIn', options: vOption6 },
& && &{ elements: s3, properties: 'custom.slideUpIn', options: vOpt },
& && &{ elements: s4, properties: 'custom.slideLeftIn', options: vOpt },
& && &{ elements: s5, properties: 'custom.slideRightIn', options: vOption6 },
& & $.Velocity.RunSequence(velocitySequence);
& & // Page load animation
& & box.css('opacity', 0);
& & velocitySequence = [
& && &{ elements: seq1, properties: ani1, options: vOpt },
& && &{ elements: seq2, properties: ani2, options: vOpt },
& && &{ elements: seq3, properties: ani1, options: vOpt },
& && &{ elements: seq4, properties: ani2, options: vOpt }
& & $.Velocity.RunSequence(velocitySequence);
} // end goVelocity()//@ sourceURL=pen.js
& & &/script&[/code]css代码:[code]html, body
& && && && &min-height: 100%;
& && &&&body
& && && && &font-family: &Open Sans& , helvetica,arial,sans-
& && && && &font-size: 13
& && && && &line-height: 160%;
& && && && &font-weight: 300;
& && && && &color: #444;
& && && && &background: #
& && &&&*, *:before, *:after
& && && && &box-sizing: border-
& && &&&img
& && && && &display:
& && && && &font-style:
& && &&&em
& && && && &font-style:
& && &&&/* Refresh, add boxes etc */
& && &&&#a
& && && && &position:
& && && && &top: 20
& && && && &right: 20
& && && && &display:
& && && && &background: #
& && && && &color: #
& && && && &-webkit-user-select:
& && && && &user-select:
& && &&&#a i
& && && && &cursor:
& && && && &font-size: 11
& && && && &padding: 8px 10
& && && && &border: 1px dotted #
& && && && &transition: all .12s;
& && && && &margin-left: -1
& && &&&#a .fa
& && && && &font-family: &Open Sans& , sans-
& && &&&#a .fa:last-child
& && && && &background: #d00;
& && && && &border-color: #d00;
& && && && &color: #
& && &&&#a .fa:last-child:hover
& && && && &background: #a00;
& && && && &border-color: #a00;
& && &&&#btn
& && && && &text-align:
& && && && &margin-top: -30
& && &&&#btn i
& && && && &cursor:
& && && && &background:
& && && && &color: #
& && && && &padding: 0 14
& && && && &margin: 0 2
& && && && &line-height: 250%;
& && && && &display: inline-
& && && && &transition: all .2
& && && && &border-radius: 2
& && &&&#btn i:hover
& && && && &background: #333;
& && &&&/* ----- end defaults ---- */
& && &&&/* Main layout */
& && &&&#boxes
& && && && &padding-bottom: 1000
& && &&&#boxes, h1, pre
& && && && &width: 660
& && && && &margin: 40
& && && && &text-align:
& && && && &position:
& && &&&#boxes
& && && && &width:
& && && && &max-width: 850
& && && && &text-align:
& && &&&/*#boxes, .box&&{ transform: translate3d(0,0,0); }*/
& && &&&/* Headers */
& && &&&h1, h2
& && && && &font-size: 21
& && && && &line-height: 100%;
& && && && &font-weight: 300;
& && &&&h1
& && && && &font-size: 24
& && && && &font-weight: 700;
& && && && &border-bottom: 1px solid #
& && &&&h1 i
& && && && &font-weight: 300;
& && &&&pre
& && && && &display:
& && && && &margin-top: -25
& && && && &text-transform:
& && && && &color: #888;
& && && && &font-size: 11
& && && && &letter-spacing: .5
& && &&&pre i
& && && && &cursor:
& && && && &display: inline-
& && && && &margin: 0 0 0 3
& && &&&pre i:hover
& && && && &color: #222;
& && &&&pre span
& && && && &color: #
& && && && &display:
& && && && &letter-spacing: 0;
& && &&&/* Paddings / Margins */
& && &&&h1
& && && && &padding: 20px 0;
& && &&&h2, h3
& && && && &margin: 0 0 12
& && &&&h3
& && && && &font-size: 12
& && && && &white-space:
& && && && &width:
& && && && &overflow:
& && && && &text-overflow:
& && && && &display:
& && && && &margin-top: 4
& && &&&.box
& && && && &margin: 0 15px 30
& && &&&/* inline-block adds +4px margin */
& && &&&.box img.full
& && && && &margin: -1px 0 9px -1
& && &&&.box a
& && && && &color:
& && && && &text-decoration:
& && && && &border-bottom: 1px dotted #
& && &&&.box a:hover
& && && && &border-color:
& && && && &color:
& && &&&/* Boxes */
& && &&&.box
& && && && &height: 150
& && && && &_opacity: 0;
& && && && &display:
& && && && &text-align:
& && && && &border: 1px solid #
& && && && &border-bottom: 1px solid #
& && && && &background: #
& && && && &width: 240
& && && && &height:
& && && && &display: inline-
& && &&&.boxRight
& && && && &_padding: 15px 40px 0 0;
& && && && &padding: 0 20
& && && && &text-align:
& && &&&.boxRight h3
& && && && &margin-bottom: 0;
& && &&&.boxRight i
& && && && &display:
& && && && &font-size: 11
& && && && &color: #888;
& && && && &font-style:
& && && && &margin: 0 0 10px 0;
& && &&&.boxRight i span
& && && && &font-family: georgia,
& && && && &font-style:
& && && && &font-size: 11
& && && && &color: #
Powered by就像许多开发者确信的那样,在Web上使用CSS实现动画并不是唯一的方式,我们也可以使用JS来实现,并且JS还有一些CSS无法替代的优势。
然而抛开JS而选择CSS来实现动画,将以样式表内容膨胀,丧失对动画时间的控制为代价,并且无法灵活地实现基于物理运动模型的动画设计。
不要误导我! CSS动画在Web中扮演重要的角色-----独自的实现动画或是同JS协作实现。 特别的,CSS在一些简单基本的动画交互上表现的特别好,比如hover和focus等。(作者的意思是:客观的看待CSS动画和JS动画,他们各有优点)
然而,对于几乎所有事情,JS都是不错的选择,因为他的能力太强大了。
如果我说JS的动画性能比CSS出色,你可能不会相信我。可能你曾经有使用jQuery设计动画的糟糕经历,比如动画出现抖动、不平滑,然后草率地归咎于JS语言。
完全不对,不要混淆JS和jQuery这俩种不同的生物。
jQuery 是由许多原生JS写的函数组成的库,就像C++的标准库一样。jQuery原本不是以动画引擎为目标设计的,而是为了使烦人的DOM操作变得方便高效(效果确实令人惊讶).
幸运的是目前就有一些开源的动画库,使得你可以绕开jQuery去利用原生JS那令人惊叹的魔力。通过这些动画库,您可以建立一个可控的动画工作流,而且这一切都基于能大幅提升网站动画性能的特征层之上。
我将带领你快速地了解,以便于你设计炫目平滑并且易配置的动画。
Velocity专为动画而设计 ,简单易用,功能强大,广泛地被一些主流公司所使用(包括,
and )。并且Velocity 是基于许可协议的开源库。
Velocity模仿了jQuery的语法,可以完美地同jQuery协作,当然也能独立地使用,所以对你来说应该很容易学。由于jQuery使用普遍,我也将向你展示Velocity如何同它协作。
Note: 为了提高你所有动画的性能,只需要简单地将目前jQuery的animate()函数调用换成velocity(),因为Velocity将原来jQueryanimate()函数的语法和功能在velocity()函数内部都做了解释映射,所以能兼容以前animate()的使用方式(velocity()还扩展了animate()的功能)。但即使是这样的一个小改变,也能使你的网站有一个显著的性能提升。
Velocity还有许多需要了解的地方。在我们深入之前,让我们快速地了解一下他能干什么,以便让你明白他的价值。
下面是一些不可能用CSS简单实现的JS动画。
现在有一个流行的Web设计,即在一个长页面中有序放置所有内容,只需轻微滑动一下鼠标,窗口就会平滑地滚动到恰当的页面区域,而不是像传统一样导航到另一个不同的页面。这是JS动画最流行的一种应用,并且无法用CSS实现。
而在Velocity里,你只需在目标元素上调用velocity()方法并传入"scroll"命令和过渡时间:
$element.velocity("scroll", 1000);
这个方法将使浏览器滚动到选定的元素(jQuery对象,$element),过渡时间为1000ms。仅使用jQuery实现这个功能也会很复杂,而且将用到多个函数操作。
对于这条代码不太明白也没有关系;我们将在了解velocity几个巧妙的功能之后慢慢弄懂他。
在jQuery中,想要使元素恢复成动画运行之前的状态,你必须手动的设置元素原来的属性值,比如:
$element.animate({ width: "100px" }, 400);
又使元素在400ms内回复成原来50px的宽度
$element.animate({ width: "50px" }, 400);
相较地,在Velocity里只是一个运行"reversr"命令:
先将宽度变到100px
$element.velocity({ width: "100px" }, 400);
//在400ms内回到原来的状态
$element.velocity("reverse");
$element.velocity("reverse");这条命令将使$element回到运行$element.velocity({ width: "100px" }, 400);前的状态,而你不用手动的去设置目标 width (50px).
现实世界的运动模型既不是线性的也不是平滑的。它有快速的部分,有慢的部分,可能存在摩擦,甚至需要考虑重量。使用JS可以很好地模拟这些运动,并且看起来非常的自然。而线性的运动效果看起来则非常机械,不怎么中看。
为了方便模拟现实世界的运动,Velocity提供弹性动画功能(spring),以一个张弛度(默认500)和一个摩擦系数(默认值20)作为他的参数(参考获取更多信息)
$element.velocity({ width: "100px"}, [ 1000, 40 ]);
较高的张弛度将提高整体速度和动画的反弹力度,较小的摩擦系数将提高动画结束时的速度。(较大的摩擦系数将使动画快速减速)。调整这些值会让每个动画独一无二,逼真并且有趣。(具体操作一下感觉更直观)
上面那个示例运行起来应该非常快,非常灵动(因为设置了较大的张弛度),并且将快速减速,在接近动画末尾的时候速度将变得很慢。(因为设置了较大的摩擦系数)。
PS:小编在这里解释一下,spring是动画选项中easing的一个可选值,至于easing是什么在后面有介绍。这里仅仅解释一下spring到底是什么玩意儿。准确的讲spring对应一个JS函数,而这个函数描述的是一个运动模型,什么模型呢?答案是弹簧振子模型,想必大家初中的时候就做过这种物理题了。spring的俩个参数---张弛度和摩擦系数,其实就对应弹簧的初始弹性势能和地面的摩擦系数。大家自己都可以把这个模型写出来。
已经听够他能做什么了!今天让我们来探究一下怎么去用它。就像我之前提到的一样,Velocity可以独立使用,也可以和jQuery一起使用以获得一个快速高效的结果(因为jQuery使得选择元素变得非常容易)。
第一步是下载,然后包含到你的页面中去(原文的叙述考虑到文档是否解析完毕的问题,特别提到应将它放到&/body&之前)
&script src="///jquery-2.1.1.min.js"&&/script&&script src="//cdn.jsdelivr.net/velocity/1.1.0/velocity.min.js"&&/script&
Note: 如果你正在使用jQuery,确保载入jQuery的script标签出现在载入velocity的script标签之前,因为velocity需要根据是否使用jQuery来调整他的API。一旦使用了velocity,你可以在使用jQueryanimate的地方使用它的基本功能。然而想要充分使用它的强大功能的话还有几个附加设置。比如animation reversals, transforms, spring physics, chaining, and color animations(所有这些将在下面讲到)。但这还不是所有,查看获取更多的信息。
现在让我们看看velocity真正的语法到底是什么样的。(之前都是类jQuery的)
Velocity 接收一个或更多的参数,只有第一个参数是是强制要求的,它可以是一个命令(就像上面例子中的”scroll”),或者是由CSS属性值组成的对象(这些值是动画的目标值):
$element.velocity({ opacity: "50%", left: "500px"});
第二个参数是由动画附加选项组成的对象,比如过渡时长,张弛度,延时还有回调函数。
// 200ms之后在200ms的时间内,透明度变到50%
$element.velocity({ opacity: "50%" }, { delay: 200, duration :200 });
另外作为一种可选的快捷方式,你可以以任何顺序以逗号隔开的形式传递时长,张弛度(easing)和回调函数中的一个或多个参数,然而如果你想再传入其他动画选项的话必须使用数据对象的形式,而且这俩种方式不能混合使用。对于这里小编举几个例子说明:
//200ms的时长,easing是swing,最后加个回调函数
$element.velocity({left:”1000px”},200,”swing”,function(){console.log(“ok”)});
//等价于$element.velocity({left:”1000px”},{“duration”:200,”easing”:”swing”,”complete”:function(){console.log(“ok”);})
//下面这个用法是错的,俩种风格不能混用
$element.velocity({ left: "50px" }, 500, "ease-in-out", function () { alert("done") }, { delay: 200 });
$element.velocity({left:”50px”},{“easing”:”ease-in-out”,”duration”:500,”complete”:function(){alert(“done”);}});
Note: 第二类参数是可选择的(原文是第二个参数,但从上面的例子可以看出可以是不止俩个参数,从参数分类上却恰好是俩类,所以小编这里将其译为第二类(properties和options俩类,在其官方文档中可以看出来)),因为对于那些重要的属性都有默认值,比如easing的默认值是swing,duration的默认值是400ms。所有其他的动画选项都是可选的。
同时你只能为每一个CSS属性设置一个值,所以 “padding:’10px 15px’”这样的设置是不合法的。替代做法是单独设置每一个分属性:{paddingLeft:”10px”,paddingTop:”15px”,….}。这样不仅表达清晰,而且意味着你可以特别指定每一个css分属性的值,而不是只设置一个整体的,给予了你足够的空间定制动画。
Note: 有多个单词描述的CSS属性(比如font-size和padding-left)必须使用骆驼拼写法表示(fontSize&&paddingLeft).
如果CSS属性值没有给定确切的单位,那么时间默认是:ms,长度默认是px,角度默认是deg。为了表达清晰最好还是显示注明单位,那样以后再看代码时也容易理解。如果有一个值不仅仅由数字表示,那么必须加引号。比如:duration:500(默认是500ms)是合法的,但是duration:500ms就不合法,必须加上引号:duration:”500ms”.
JS动画运许传入简单的表达式作为CSS的属性值,但这些表达式只限于:+=,-=,*=,/=,表示目标值在其本来的值的基础上加多少,减多少,乘多少,除多少,任何其他的表达式是不允许的。实例:
$element.velocity({
width: "+= 50px", // Adds 50px to the current width value
eight: "/= 2" // divides the current height value by two
表示动画完成后width比原值大50px,height变为原来的二分之一。
在Velocity动画引擎里使用这些快速功能保证了动画的逻辑可读性,使代码简洁清晰(消除了值的手工计算),而且向Velocity引擎提供更多有关于你动画意图的信息将有助于提高动画的性能。动画逻辑包含的越多,Velocity就能更好地提高代码的性能。
Velocity的链式调用即在同一个元素上一个动画完成之后马上进入另一个动画,这样一个一个的执行下去:
.velocity({ width: "500px", height: "300px"})
.velocity({ opacity: 0 });
$element.velocity({ width: "500px", height: "300px"});
$element.velocity({ opacity: 0 });
就如之前提到的一样,这允许你不需要任何手动的计算,就能使那些复杂的、有时间限制的多级动画如当初计划的一样,一个接一个的执行。
我已经在文章里多次提到easing这个词了,或许你一直想弄明白它究竟是什么意思。easing是一些数学函数,他们决定了一个动画在不同阶段的速度(其实就是物理的运动模型)。比如:ease-in-out表示先加速再减速。linear表示匀速。
你可以在easing选项里指定easing的类型;
$element.velocity({ top: 100 }, { easing: "ease-in-out" });
easing也是使用之前提到的弹性动画的一种方式。你可以只传入spring来使用它(默认张弛度500,阻力系数:20),也可以像下面那样手动指定参数来使用:
$element.velocity({ width: 500 }, { easing: [ 250, 10 ] });
easing还有很多复杂难懂的内容,因为文章篇幅的原因,也就只介绍到这里。更多的信息可以从官方文档中获取。
Velocity 允许制作基于颜色变换的动画,比如:color,backgroundColor,borderColor还有outlineColor.所有这些颜色的值只允许是16进制的字符串(黑色:#000000 , 脸谱蓝:#3b5998(for Facebook blue) ).也许你想使用rgb格式的颜色设置,甚至指定颜色透明度(值介于0到1),只需简单地在CSS颜色名后面加上“Red”,“Green”,”Blue” 或者“Alpha”即可:
$element.velocity({
borderColor: "#f06d06",
backgroundColorAlpha: 0.8,//背景颜色透明度变到80%
colorBlue: 200//rgb 方式
如早些说过的一样 ,scroll命令将促使页面滚动到指定元素的上边缘,你可以向其他动画一样传递同样的附加选项,并且同样支持链式调用。
.velocity("scroll", { duration: 1000 })
.velocity({ opacity: 1 });
//默认的滚动沿y轴方向,想改到x轴方向的话可以使用axis选项:
$element.velocity("scroll", { axis: "x" });
Velocity允许你设置窗口滚动后元素上边缘距窗口上边缘的距离,你只需设置offset选项即可完成:
// 滚动之后窗口上边缘将位于元素上边缘之上100px的地方
$element.velocity("scroll", { duration: 1000, offset: "-100px" });
//滚动之后窗口上边缘将位于元素上边缘之下100px的地方
$element.velocity("scroll", { duration: 1000, offset: "100px" });
想要结合CSS和JS设计动画? 设置一些CSS变换规则,允许你做一些2D或3D的动画,比如平移,扩大,旋转。注意这些变换不会影响元素在网页中的位置,也不会影响该元素周围 的元素在页面中的位置。 Velocity支持下面的变换:
translateX: 从左向右沿x轴移动元素
translateY: 从上到下沿y轴移动元素
rotateZ: 关于z轴旋转元素
rotateX: 关于x轴旋转元素(看起来由里向外)
rotateY: 关于y轴旋转元素(由左到右)
scaleX: 成倍数改变元素宽度
scaleY: 成倍数改变元素高度
$element.velocity({
rotateZ: "90deg", // rotate clockwise 90 degrees
scaleX: 2.0 // double the width
动画使得静态页面更具交互性,更加栩栩如生,而JS动画则是最好的实现方式。 CSS动画可选的功能有限,更新慢;而对于JS动画,在开源世界则有一大堆库和插件,并且维护地很好。使用这些JS工具将使得你的动画设计更具有可能性。
除了在这里演示的外,Velocity还有很多其他的功能,小编强烈建议看看它的。现在就开始动手吧!:)
最后,额外的俩点:查看这个了解怎样使用Velocity的UI包来改善用户界面。还有您也可以查看的velocity 示例。
阅读(...) 评论()

我要回帖

更多关于 小米note4上市时间 的文章

 

随机推荐