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

[代码片段] jQuery - UI

[复制链接]

[代码片段] jQuery - UI

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

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

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

x
1.jQuery UI

   1. 分类

     1. Effects 效果

       * 扩展jQuery中的animate()方法,可以使用扩展一下样式属性

         * backgroundColor

         * borderBottomColor

         * borderLeftColor

         * borderRightColor

         * borderTopColor

         * Color

         * outlineColor

       * effect()方法 - 提供各种各样的效果

例如:

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

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

  5.   <title>jQueryUI扩展animate方法</title>

  6.   <!-- 1. 引入jQuery文件 -->

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

  8.   <!-- 2. 引入jQuery UI的JS文件 -->

  9.   <script src="jquery-ui.js"></script>

  10.   <!-- 3. 引入jQuery UI的CSS文件 -->

  11.   <link rel="stylesheet" href="jquery-ui.css">

  12.   <style>

  13. div {

  14. width : 200px;

  15. height : 200px;

  16. background-color : pink;

  17. position:absolute;

  18. }

  19.   </style>

  20. </head>

  21. <body>

  22.   <div></div>

  23.   <script>

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

  25. backgroundColor : "green",

  26. left:300

  27. },3000).animate({

  28. backgroundColor : "blue",

  29. top:300,

  30. },3000).animate({

  31. backgroundColor : "red",

  32. left:500,

  33. },3000).animate({

  34. backgroundColor : "yellow",

  35. width:150,

  36. height:150,

  37. },3000);

  38.   </script>

  39. </body>

  40. </html>
复制代码
效果:

231103b0ca36sp6jpm6kam.png 231103b0ca36sp6jpm6kam.png

231103b0ca36sp6jpm6kam.png 231103b0ca36sp6jpm6kam.png




     2. 组件

         * Dialog - 对话框

例如:

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

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

  5.   <title>动态打开对话框</title>

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

  7.   <script src="jquery-ui.js"></script>

  8.   <link rel="stylesheet" href="jquery-ui.css">

  9. </head>

  10. <body>

  11.   <button>打开对话框</button>

  12.   <div id="dialog" title="对话框">

  13. <p>这是一个具有样式的对话框.</p>

  14.   </div>

  15.   <script>

  16. $("button").button().click(function(){

  17. $("#dialog").dialog("open");

  18. });

  19. /*

  20.    dialog(options)函数

  21.    * 作用 - 实现一个对话框的样式

  22.    * 选项

  23.      * autoOpen - 是否自动打开,Boolean值

  24. * show - 表示设置显示对话框的动画效果

  25. * hide - 表示设置隐藏对话框的动画效果

  26. * modal - 表示是否为模式对话框,Boolean

  27. * width和height - 设置对话框的宽高

  28. * buttons - 表示设置button

  29. */

  30. $("#dialog").dialog({

  31. autoOpen : false,

  32. modal : true,

  33. //width : 800,

  34. //height : 500,

  35. show : {

  36. effect : "fade",

  37. duration : 500

  38. },

  39. hide : {

  40. effect : "blind",

  41. duration : 500

  42. },

  43. buttons : [

  44. {

  45. text : "确认",

  46. click : function(){

  47. $("#dialog").dialog("close");

  48. }

  49. },

  50. {

  51. text : "取消",

  52. click : function(){

  53. $("#dialog").dialog("close");

  54. }

  55. }

  56. ]

  57. });

  58.   </script>

  59. </body>

  60. </html>
复制代码
效果:

231103b0ca36sp6jpm6kam.png

点击 打开对话框:

231103b0ca36sp6jpm6kam.png

点击 确认 后,对话框消失。



   * 交互

     * 拖拽

       * Draggable - 拖动

       * Droppable - 投放

         * 排序(Sortable)

         * 缩放(Resizable)

         * 选择(Selectable)



例如:

  1. <!doctype html>

  2. <html lang="en">

  3. <head>

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

  5.   <title>Droppable</title>

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

  7.   <script src="jquery-ui.js"></script>

  8.   <link rel="stylesheet" href="jquery-ui.css">

  9.   <style>

  10. #draggable { width: 100px; height: 100px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }

  11. #droppable { width: 150px; height: 150px; padding: 0.5em; float: left; margin: 10px; }

  12.   </style>

  13. </head>

  14. <body>

  15.     <div id="draggable" class="ui-widget-content">

  16. <p>Drag me to my target</p>

  17. </div>



  18. <div id="droppable" class="ui-widget-header">

  19. <p>Drop here</p>

  20. </div>

  21. <script>

  22. // 被拖动的元素 - 称之为源元素

  23. $("#draggable").draggable();

  24. // 拖拽到的元素 - 称之为目标元素

  25. $("#droppable").droppable({

  26. // 指定源元素

  27. accept: "#draggable",

  28. // 活动时的样式

  29. activeClass: "ui-state-highlight",

  30. // 投放事件

  31. drop : function(event,ui){

  32. $( this )

  33. .addClass( "ui-state-highlight" )

  34. .find( "p" )

  35. .html( "Dropped!" );

  36. }

  37. });

  38. </script>

  39. </body>

  40. </html>
复制代码
效果:

231103b0ca36sp6jpm6kam.png

拖动后:

231103b0ca36sp6jpm6kam.png

回复

使用道具 举报


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

本版积分规则

手机版| 赣南网

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

用微信扫一扫

赣南网