+发表新主题
查看: 1876|回复: 0

[代码片段] jquery - 自定义动画

[复制链接]

[代码片段] jquery - 自定义动画

[复制链接]
殷三姗 发表于 2016-2-14 21:03:36 浏览:  1876 回复:  0 [显示全部楼层] |只看大图 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
1.自定义动画

    1.animate(properties,duration,easing,callback)

     * properties - 设置相关动画需要的CSS的属性内容

     * duration - 设置自定义动画执行的时长(毫秒)

     * easing - 要使用的擦除效果的名称(需要插件支持).默认jQuery提供"linear" "swing".

     * callback - 自定义动画执行完毕后的回调函数



例如:

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

  4.   <meta charset="UTF-8">

  5.   <title>jQuery自定义动画一</title>

  6.   <script src="jquery-1.11.3.js"></script>

  7.   <style>

  8. div {

  9. width : 200px;

  10. height : 200px;

  11. border : solid 1px black;

  12. background : pink;

  13. position : absolute;

  14. top : 100px;

  15. left : 100px;

  16. }

  17.   </style>

  18. </head>

  19. <body>

  20.   <div></div>

  21.   <script>

  22. $("div").animate({

  23. width : 100,

  24. height : 100,

  25. top : 300,

  26. left : 300

  27. },3000,function(){

  28. alert("hello world!!");

  29. });

  30.   </script>

  31. </body>

  32. </html>
复制代码
效果如下:

203752z0444488l049nx84.png

203752z0444488l049nx84.png


   2.animate(properties,options)

     * properties - 设置相关动画需要的CSS的属性内容

     * options - 选项

       * duration - 设置自定义动画执行的时长(毫秒)

       * easing - 要使用的擦除效果的名称(需要插件支持).默认jQuery提供"linear" "swing".

       * complete - 自定义动画执行完毕后的回调函数

       * queue - Boolean,(默认值: true) 设定为false将使此动画不进入动画队列


例如:

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

  4.   <meta charset="UTF-8">

  5.   <title>jQuery自定义动画一</title>

  6.   <script src="jquery-1.11.3.js"></script>

  7.   <style>

  8. div {

  9. width : 200px;

  10. height : 200px;

  11. border : solid 1px black;

  12. background : pink;

  13. position : absolute;

  14. top : 100px;

  15. left : 100px;

  16. }

  17.   </style>

  18. </head>

  19. <body>

  20.   <div></div>

  21.   <script>

  22. $("div").animate({

  23. width : 100,

  24. height : 100,

  25. top : 300,

  26. left : 300

  27. },{

  28. duration : 3000,

  29. complete : function(){

  30. alert("hello world!!");

  31. }

  32. })

  33.   </script>

  34. </body>

  35. </html>
复制代码
效果与上一样。


   * 注意 - 有些CSS的属性不能使用

     * backgroundColor

     * borderBottomColor

     * borderLeftColor

     * borderRightColor

     * borderTopColor

     * Color

     * outlineColor

   * 排队与并发效果

     * 并发效果 - 指多个动画同时执行

  

例如:  

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

  4.   <meta charset="UTF-8">

  5.   <title>jQuery自定义动画 -- 并发</title>

  6.   <script src="jquery-1.11.3.js"></script>

  7.   <style>

  8.         div {

  9.                 width : 200px;

  10.                 height : 200px;

  11.                 border : solid 1px black;

  12.                 background : pink;

  13.                 position : absolute;

  14.                 top : 100px;

  15.                 left : 100px;

  16.         }

  17.   </style>

  18. </head>

  19. <body>

  20.   <div></div>

  21.   <script>

  22.         $("div").animate({

  23.                 width : 100,

  24.                 height : 100

  25.         },{

  26.                 duration : 3000

  27.         }).animate({

  28.                 left : 500

  29.         },{

  30.                 duration : 3000,

  31.                 queue : false

  32.         }).animate({

  33.                 top :500

  34.         },{

  35.                 duration : 3000,

  36.                 queue : false

  37.         }).hide(3000);

  38.   </script>

  39. </body>

  40. </html>
复制代码
     * 排队效果 - 指多个动画按照先后顺序执行

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

  4.   <meta charset="UTF-8">

  5.   <title>jQuery自定义动画 -- 排队效果</title>

  6.   <script src="jquery-1.11.3.js"></script>

  7.   <style>

  8.         div {

  9.                 width : 300px;

  10.                 height : 300px;

  11.                 border : solid 1px black;

  12.                 background : pink;

  13.                 position : absolute;

  14.                 top : 100px;

  15.                 left : 100px;

  16.         }

  17.   </style>

  18. </head>

  19. <body>

  20.   <div></div>

  21.   <script>

  22.         $("div").animate({

  23.                 width : 100,

  24.                 height : 100

  25.         }).animate({

  26.                 left : 500

  27.         },{

  28.                 duration : 3000

  29.         }).animate({

  30.                 top : 500

  31.         },{

  32.                 duration : 3000

  33.         })

  34.   </script>

  35. </body>

  36. </html>
复制代码
回复

使用道具 举报


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版| 赣南网

© 2013-2016 Comsenz Inc. Powered by Discuz! X3.4

用微信扫一扫

赣南网