{"id":628,"date":"2008-11-08T23:11:55","date_gmt":"2008-11-08T15:11:55","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/628.aspx"},"modified":"2008-11-09T00:11:17","modified_gmt":"2008-11-08T16:11:17","slug":"Mootools+1.2%e6%95%99%e7%a8%8b(16)%e2%80%94%e2%80%94%e6%8e%92%e5%ba%8f%e7%b1%bb%e5%92%8c%e6%96%b9%e6%b3%95%e7%ae%80%e4%bb%8b","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/628","title":{"rendered":"Mootools 1.2\u6559\u7a0b(16)\u2014\u2014\u6392\u5e8f\u7c7b\u548c\u65b9\u6cd5\u7b80\u4ecb"},"content":{"rendered":"<h2>MooTools 1.2\u7684\u6574\u7406\u6392\u5e8f\u7c7bSortables<\/h2>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.consideropen.com\/blog\/2008\/09\/30-days-of-mootools-12-tutorials-day-16-sortables30-days-of-mootools-12-tutorials-day-16-sortables-and-intro-to-methods\/\" target=\"_blank\" title=\"30 Days of Mootools 1.2 Tutorials - Day 16 - Sortables and Intro to Methods\">30 Days of Mootools 1.2 Tutorials &#8211; Day 16 &#8211; Sortables and Intro to Methods<\/a><\/p>\n<p>\u8bf7\u5c0a\u91cd\u4e2a\u4eba\u52b3\u52a8\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttp:\/\/fdream.net\uff0c\u8bd1\u8005\uff1aFdream<\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u51c6\u5907\u597d\u5f00\u59cb\u8fd9\u4e00\u8bb2\uff0c\u8bf7\u53c2\u8003\u8fd9\u4e00\u7cfb\u5217\u7684\u6559\u7a0b\uff0c\u8fd9\u91cc\u662f<a href=\"http:\/\/fdream.net\/blog\/article\/605.aspx\" target=\"_blank\" title=\"\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b\">\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b<\/a>\u3002<\/p>\n<p>\u4ece\u4eca\u5929\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u5f00\u59cb\u8bb2\u89e3\u201c\u66f4\u591a\u201d\uff08more\uff09\u5e93\u91cc\u9762\u7684\u66f4\u591a\u63d2\u4ef6\u3002Sortables\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u63d2\u4ef6\uff0c\u80fd\u591f\u771f\u6b63\u5730\u6269\u5927\u4f60\u7684\u7528\u6237\u754c\u9762\u8bbe\u8ba1\u7684\u9009\u62e9\u9762\u3002Sortables\u7c7b\u8fd8\u63d0\u4f9b\u4e86\u5305\u62ec\u4e00\u4e2a\u540d\u53eb\u201cserialize\u201d\u7684\u4f18\u79c0\u65b9\u6cd5\uff0c\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u4f60\u989d\u53ef\u4ee5\u628a\u8fd9\u4e9b\u5143\u7d20\u7684id\u4f5c\u4e3a\u6570\u7ec4\u8f93\u51fa\u2014\u2014\u5bf9\u4e8e\u670d\u52a1\u5668\u7aef\u7684\u5f00\u53d1\u975e\u5e38\u6709\u7528\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u770b\u770b\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6392\u5e8f\u9879\u96c6\u5408\uff0c\u8fd8\u6709\u4e00\u5b9a\u8981\u770b\u4e00\u4e0b\u6700\u540e\u7684\u6f14\u793a\u5b9e\u4f8b\u3002<\/p>\n<h3>\u57fa\u672c\u77e5\u8bc6<\/h3>\n<h4>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Sortable\u5bf9\u8c61<\/h4>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u628a\u6211\u4eec\u8981\u6392\u5e8f\u7684\u5143\u7d20\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002\u5bf9\u4e8eSortables\u6765\u8bf4\uff0c\u5982\u679c\u4f60\u60f3\u8981\u591a\u4e2a\u5217\u8868\u4e4b\u95f4\u7684\u5143\u7d20\u80fd\u591f\u5728\u76f8\u4e92\u4e4b\u95f4\u62d6\u62fd\uff0c\u4f60\u9700\u8981\u628a\u8fd9\u4e9b\u5143\u7d20\u5168\u90e8\u90fd\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar sortableListsArray = $$('#listA, #listB');\n<\/pre>\n<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u628a\u4e24\u4e2aul\u7684id\u653e\u5230\u4e00\u4e2a\u6570\u7ec4\u91cc\u9762\u4e86\u3002\u6211\u4eec\u73b0\u5728\u5c31\u53ef\u4ee5\u4ece\u8fd9\u4e2a\u6570\u7ec4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684sortable\u5bf9\u8c61\u4e86\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray);\n<\/pre>\n<\/p>\n<p>\u6211\u4eec\u5047\u8bbe\u4f7f\u7528\u7684\u662f\u4e0b\u9762\u7684HTML\uff1a<\/p>\n<p><pre lang=\"html\">\n&lt;ul id=&quot;listA&quot;&gt;\n    &lt;li&gt;Item A1&lt;\/li&gt;\n    &lt;li&gt;Item A2&lt;\/li&gt;\n    &lt;li&gt;Item A3&lt;\/li&gt;\n    &lt;li&gt;Item A4&lt;\/li&gt;\n&lt;\/ul&gt;\n \n&lt;ul id=&quot;listB&quot;&gt;\n    &lt;li&gt;Item B1&lt;\/li&gt;\n    &lt;li&gt;Item B2&lt;\/li\n    &lt;li&gt;Item B3&lt;\/li&gt;\n    &lt;li&gt;Item B4&lt;\/li&gt;\n&lt;\/ul&gt;\n<\/pre>\n<\/p>\n<p>\u6211\u4eec\u7684sortable\u5217\u8868\u6700\u540e\u770b\u8d77\u6765\u5927\u6982\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>\n<script type=\"text\/javascript\">\nwindow.addEvent('domready', function() {\nvar sortableListsArray = $$('#listA, #listB');\nvar sortableLists = new Sortables(sortableListsArray);\n});\n<\/script><\/p>\n<ul id=\"listA\">\n<li>Item A1<\/li>\n<li>Item A2<\/li>\n<li>Item A3<\/li>\n<li>Item A4<\/li>\n<\/ul>\n<ul id=\"listB\">\n<li>Item B1<\/li>\n<li>Item B2<\/li>\n<li>Item B3<\/li>\n<li>Item B4<\/li>\n<\/ul>\n<h3>Sortables\u9009\u9879<\/h3>\n<p>\u5982\u679c\u4f60\u60f3\u5b8c\u5168\u5b9a\u4e49\u4f60\u81ea\u5df1\u7684sortable\u5217\u8868\uff0c\u4f60\u5c31\u9700\u8981\u4f7f\u7528\u8fd9\u4e9b\u9009\u9879\u3002<\/p>\n<h4>constrain<\/h4>\n<p>\u9ed8\u8ba4\u2014\u2014false<\/p>\n<p>\u8fd9\u4e2a\u9009\u9879\u51b3\u5b9a\u4e86\u4f60\u7684sortable\u5217\u8868\u5143\u7d20\u662f\u5426\u53ef\u4ee5\u5728\u591a\u4e2aul\u4e4b\u95f4\u62d6\u52a8\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u5728\u4e00\u4e2asortable\u5bf9\u8c61\u4e2d\u6709\u4e24\u4e2aul\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u9009\u9879\u201cconstain:true\u201d\u6765\u201c\u9650\u5236\u201d\uff08constrain\uff09\u5217\u8868\u7684\u5143\u7d20\u53ea\u5141\u8bb8\u5728\u5b83\u4eec\u7684\u7236\u8282\u70b9ul\u4e4b\u5185\u79fb\u52a8\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray, {\n    constrain: false \/\/ \u9ed8\u8ba4\u4e3afalse\n});\n<\/pre>\n<\/p>\n<h4>clone<\/h4>\n<p>\u9ed8\u8ba4\u2014\u2014false<\/p>\n<p>\u514b\u9686\uff08clone\uff09\u9009\u9879\u5141\u8bb8\u4f60\u6dfb\u52a0\u4e00\u4e2a\u201cclone\u201d\u7684\u5143\u7d20\u8ddf\u968f\u4f60\u7684\u9f20\u6807\u79fb\u52a8\uff0c\u800c\u628a\u539f\u59cb\u7684\u5143\u7d20\u7559\u5728\u539f\u5730\u4e0d\u52a8\u3002\u4f60\u53ef\u4ee5\u4ece\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u770b\u770b\u5982\u4f55\u4f7f\u7528clone\u9009\u9879\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray, {\n    clone: true \/\/ \u9ed8\u8ba4\u4e3afalse\n});\n<\/pre>\n<\/p>\n<h4>handle<\/h4>\n<p>\u9ed8\u8ba4\u2014\u2014false<br \/>handler\u9009\u9879\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u62d6\u52a8\u7684\u63a7\u5236\u5668\u3002\u5982\u679c\u4f60\u8981\u4fdd\u6301\u4f60\u7684\u5217\u8868\u4e2d\u7684\u6587\u672c\u53ef\u4ee5\u88ab\u9009\u4e2d\u6216\u8005\u4fdd\u7559li\u7684\u5176\u4ed6\u884c\u4e3a\uff0c\u4f7f\u7528\u8fd9\u4e2a\u53c2\u6570\u5219\u975e\u5e38\u65b9\u4fbf\u3002\u9ed8\u8ba4\u53c2\u6570\u4e3afalse\u5219\u4f1a\u4f7f\u5f97\u6574\u4e2a\u5143\u7d20\uff08li\uff09\u6210\u4e3a\u63a7\u5236\u5668\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar handleElements = $$('.handlesClass');\nvar sortableLists = new Sortables(sortableListsArray, {\n    handle: handleElements \/\/ \u9ed8\u8ba4\u4e3afalse\n});\n<\/pre>\n<\/p>\n<h4>opacity<\/h4>\n<p>\u9ed8\u8ba4\u2014\u20141<\/p>\n<p>\u4e0d\u900f\u660e\u5ea6\uff08opacity\uff09\u9009\u9879\u53ef\u4ee5\u8ba9\u4f60\u8c03\u6574\u6392\u5e8f\u5143\u7d20\u3002\u5982\u679c\u4f60\u4f7f\u7528\u4e86\u4e00\u4e2aclone\u7684\u526f\u672c\uff0copacity\u5c06\u4f5c\u7528\u4e8e\u8fd9\u4e2a\u6392\u5e8f\u5143\u7d20\uff0c\u800c\u4e0d\u662f\u66f4\u968f\u4f60\u9f20\u6807\u7684\u90a3\u4e2a\u526f\u672c\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray, {\n    opacity: 1 \/\/ \u9ed8\u8ba4\u4e3a1\n});\n<\/pre>\n<\/p>\n<h4>revert<\/h4>\n<p>\u9ed8\u8ba4\u2014\u2014false<\/p>\n<p>\u590d\u539f\uff08revert\uff09\u53c2\u6570\u53ef\u4ee5\u63a5\u53d7\u201cfalse\u201d\u6216\u8005Fx\u7684\u9009\u9879\u503c\u3002\u5982\u679c\u4f60\u7ed9revert\u53c2\u6570\u8bbe\u7f6e\u4e86Fx\u7684\u9009\u9879\uff0c\u90a3\u4e48\u5f53\u5143\u7d20\u653e\u7f6e\u5230\u4e00\u4e2a\u4f4d\u7f6e\u65f6\u4f1a\u5e94\u7528\u76f8\u5e94\u7684Fx\u8bbe\u7f6e\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u8bbe\u7f6e\u201cduration:long\u201d\uff0c\u90a3\u4e48\u5f53\u4f60\u677e\u5f00\u9f20\u6807\u65f6\uff0c\u90a3\u4e2a\u514b\u9686\u7684\u5bf9\u8c61\u5c06\u4f1a\u5728\u8fd9\u4e2a\u65f6\u95f4\u4e4b\u5185\u8fd4\u56de\u5230\u5b83\u7684\u4f4d\u7f6e\u3002\u5982\u679c\u8981\u770brevert\u7684\u6548\u679c\uff0c\u53ef\u4ee5\u770b\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray, {\n    revert: false \/\/ \u9ed8\u8ba4\u4e3afalse\n});\n \n\/\/ \u4f60\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3aFx\u9009\u9879\nvar sortableLists = new Sortables(sortableListsArray, {\n    revert: {\n        duration: 50\n    }\n});\n<\/pre>\n<\/p>\n<h4>snap<\/h4>\n<p>\u9ed8\u8ba4\u2014\u20144<\/p>\n<p>snap\u53c2\u6570\u5141\u8bb8\u4f60\u8bbe\u7f6e\u9f20\u6807\u5fc5\u9700\u62d6\u52a8\u4e86\u591a\u5c11\u4e2a\u50cf\u7d20\u4e4b\u540e\uff0c\u5143\u7d20\u624d\u4f1a\u88ab\u62d6\u52a8\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar sortableLists = new Sortables(sortableListsArray, {\n    snap: 10 \/\/ \u7528\u6237\u9700\u8981\u62d6\u52a810px\u6765\u5f00\u59cb\u62d6\u52a8\u8fd9\u4e2a\u62d6\u52a8\u5217\u8868\n});\n<\/pre>\n<\/p>\n<h3>Sortable\u4e8b\u4ef6<\/h3>\n<p>sortable\u4e8b\u4ef6\u975e\u5e38\u597d\u4e5f\u975e\u5e38\u7b80\u5355\u6613\u7528\u3002\u6bcf\u4e00\u4e2a\u90fd\u4f1a\u4f20\u9012\u5f53\u524d\u62d6\u52a8\u7684\u5143\u7d20\uff08\u5982\u679c\u4f60\u4f7f\u7528\u4e86colone\u5143\u7d20\uff0c\u4e0d\u662f\u90a3\u4e2aclone\u7684\u5143\u7d20\uff0c\u800c\u662f\u539f\u59cb\u7684\u5143\u7d20\uff09\u3002<\/p>\n<ul style=\"list-style-type:disc\">\n<li>onStart\u2014\u2014\u5f53\u62d6\u52a8\u5f00\u59cb\u65f6\u89e6\u53d1\uff08\u5f53snap\u89e6\u53d1\u4ee5\u540e\uff09<\/li>\n<li>onSort\u2014\u2014\u5f53\u9879\u76ee\u6539\u53d8\u6392\u5e8f\u4ee5\u540e\u89e6\u53d1<\/li>\n<li>onComplete\u2014\u2014\u5f53\u4f60\u628a\u4e00\u4e2a\u5143\u7d20\u653e\u4e0b\u4ee5\u540e\u89e6\u53d1<\/li>\n<\/ul>\n<p>\u6211\u4eec\u4f1a\u5728\u540e\u9762\u518d\u4ed4\u7ec6\u770b\u8fd9\u4e9b\u4e8b\u4ef6\uff08\u4f60\u53ef\u4ee5\u5728\u540e\u9762\u7684\u4f8b\u5b50\u4e2d\u770b\u5230\u6548\u679c\uff09\u3002<\/p>\n<h3>Sortable\u65b9\u6cd5<\/h3>\n<p>\u5c3d\u7ba1\u6211\u4eec\u5df2\u7ecf\u4f7f\u7528\u8fc7\u5f88\u591a\u65b9\u6cd5\u4e86\uff0c\u4f46\u662f\u6211\u4eec\u4ece\u6765\u6ca1\u6709\u8be6\u7ec6\u8bb2\u8fc7\u3002\u65b9\u6cd5\u672c\u8d28\u4e0a\u8fd8\u662f\u4e00\u4e9b\u51fd\u6570\uff0c\u4e0d\u8fc7\u5b83\u4eec\u662f\u5c5e\u4e8e\u67d0\u4e00\u4e2a\u7c7b\u7684\u3002\u4e0d\u8fc7\u7b49\u6211\u4eec\u5728\u8bb2\u7c7b\u7684\u65f6\u5019\uff0c\u6211\u4eec\u4f1a\u7b2c\u4e8c\u6b21\u518d\u5efa\u7acb\u4e00\u4e2a\u901a\u7528\u7684\u6982\u5ff5\u3002\u8fd9\u4e2a\u63d2\u4ef6\uff08\u548c\u6211\u4eec\u8bb2\u8fc7\u7684\u5176\u4ed6\u63d2\u4ef6\u4e00\u6837\uff09\uff0c\u5168\u90e8\u90fd\u9075\u5faa\u4e00\u4e2a\u7c7b\u4f3c\u7684\u6a21\u5f0f\u2014\u2014\u4f7f\u7528\u201cnew\u201d\u521d\u59cb\u5316\u4e00\u4e2a\u63d2\u4ef6\uff0c\u5b9a\u4e49\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u9009\u62e9\u5668\u53c2\u6570\uff0c\u5b9a\u4e49\u4f60\u7684\u9009\u9879\uff0c\u6dfb\u52a0\u4e00\u4e9b\u4e8b\u4ef6\uff08\u548c\u5efa\u7acb\u65b0\u7684sortable\u548ctween\u7c7b\u4f3c\uff09\u3002\u8fd9\u4e2a\u6a21\u5f0f\u662f\u7c7b\u7684\u57fa\u7840\u3002\u4e00\u4e2a\u7c7b\u6700\u57fa\u7840\u7684\u5c31\u662f\u5141\u8bb8\u4f60\u4fdd\u5b58\u4e00\u4e9b\u9009\u9879\u548c\u51fd\u6570\uff0c\u4ece\u800c\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u5b83\u4eec\u3002\u65b9\u6cd5\u5c31\u662f\u4e00\u4e2a\u7c7b\u91cc\u9762\u4e00\u4e9b\u7279\u5b9a\u7684\u51fd\u6570\u3002\u5b9e\u4f8b\u7684.set()\u548c.get()\u65b9\u6cd5\u5219\u662felement\u7684\u5c5e\u6027\u6269\u5c55\u65b9\u6cd5\u3002\u5728Fx.Tween\u4e2d\uff0c.start()\u5c31\u662f\u4e00\u4e2a\u65b9\u6cd5\u3002\u4e3a\u4e86\u66f4\u6e05\u6670\u7684\u7406\u89e3\uff0c\u6211\u4eec\u770b\u770bsortable\u7684\u65b9\u6cd5\u3002<\/p>\n<h4>.detach();<\/h4>\n<p>\u901a\u8fc7.detach();\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5265\u79bb\uff08detach\uff09\u6240\u6709\u7684\u63a7\u5236\u5668\uff0c\u4ece\u800c\u4f7f\u5f97\u6574\u4e2a\u5217\u8868\u90fd\u4e0d\u53ef\u4ee5\u62d6\u52a8\u3002\u8fd9\u5bf9\u4e8e\u7981\u7528\u62d6\u52a8\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h4>.attach();<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u5c06\u628a\u63a7\u5236\u5668\u5173\u8054\u5230\u6392\u5e8f\u9879\u76ee\uff0c\u53ef\u4ee5\u5728\u4f7f\u7528.detach();\u65b9\u6cd5\u540e\u518d\u6b21\u542f\u52a8\u6392\u5e8f\u529f\u80fd\u3002<\/p>\n<h4>.addItems();<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u4f60\u6dfb\u52a0\u65b0\u7684\u9879\u76ee\u5230\u4f60\u7684\u6392\u5e8f\u5217\u8868\u4e2d\u3002\u8fd9\u4e2a\u610f\u601d\u662f\u8bf4\uff0c\u4f60\u6709\u4e00\u4e2a\u6392\u5e8f\u5217\u8868\uff0c\u7528\u6237\u53ef\u4ee5\u5411\u91cc\u9762\u6dfb\u52a0\u65b0\u7684\u9879\u76ee\uff0c\u4e00\u65e6\u4f60\u6dfb\u52a0\u4e86\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\uff0c\u4f60\u5c31\u9700\u8981\u5728\u90a3\u4e2a\u65b0\u7684\u9879\u76ee\u4e0a\u542f\u52a8\u6392\u5e8f\u529f\u80fd\u3002<\/p>\n<h4>.removeItems();<\/h4>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u4f60\u4ece\u5df2\u6709\u7684\u6392\u5e8f\u5217\u8868\u4e2d\u5220\u9664\u4e00\u4e9b\u5143\u7d20\u3002\u5f53\u4f60\u9700\u8981\u9501\u5b9a\u6392\u5e8f\u5217\u8868\u4e2d\u7684\u4e00\u4e9b\u7279\u6b8a\u7684\u9879\u76ee\u4e0d\u8ba9\u5b83\u53c2\u4e0e\u6392\u5e8f\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h4>.addLists();<\/h4>\n<p>\u9664\u4e86\u6dfb\u52a0\u4e00\u4e2a\u65b0\u9879\u5230\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u6392\u5e8f\u5217\u8868\u4e2d\uff0c\u4f60\u4e5f\u8bb8\u8fd8\u60f3\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u5217\u8868\u5230\u6392\u5e8f\u5217\u8868\u4e2d\u3002.addLists();\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u4f60\u6dfb\u52a0\u591a\u4e2a\u5217\u8868\uff0c\u8fd9\u4f7f\u5f97\u6dfb\u52a0\u591a\u4e2a\u6392\u5e8f\u5bf9\u8c61\u53d8\u5f97\u771f\u6b63\u5bb9\u6613\u3002<\/p>\n<h4>.removeLists();<\/h4>\n<p>\u53ef\u4ee5\u8ba9\u4f60\u4ece\u6392\u5e8f\u5bf9\u8c61\u4e2d\u79fb\u9664\u6574\u4e2a\u6574\u4e2a\u5217\u8868\u3002\u5f53\u4f60\u9700\u8981\u9501\u5b9a\u4e00\u4e9b\u7279\u6b8a\u7684\u5217\u8868\u65f6\uff0c\u8fd9\u4e2a\u5f88\u6709\u7528\u3002\u4f60\u53ef\u4ee5\u79fb\u9664\u4e00\u4e2a\u5217\u8868\uff0c\u4fdd\u7559\u4e0b\u6765\u7684\u5176\u4ed6\u9879\u76ee\u5219\u53ef\u4ee5\u7ee7\u7eed\u6392\u5e8f\uff0c\u4f46\u662f\u4f1a\u9501\u5b9a\u8fd9\u4e2a\u79fb\u9664\u7684\u5217\u8868\u3002<\/p>\n<h4>.serialize();<\/h4>\n<p>\u8fd9\u4e2a\u6392\u5e8f\u529f\u80fd\u975e\u5e38\u4f18\u79c0\uff0c\u4e0d\u8fc7\u5982\u679c\u4f60\u60f3\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u600e\u4e48\u529e\uff1f.serialize();\u65b9\u6cd5\u5c06\u4f9d\u7167\u5b83\u4eec\u7684\u987a\u5e8f\u8fd4\u56de\u5305\u542b\u8fd9\u4e9b\u9879\u76eeid\u7684\u6570\u7ec4\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u503c\u6765\u9009\u62e9\u4f60\u8981\u83b7\u53d6\u6570\u636e\u7684\u5217\u8868\u3002<\/p>\n<p>\u65b9\u6cd5\u7684\u5f71\u54cd\u529b\u8fdc\u8fdc\u8d85\u8fc7\u6211\u4eec\u8fd9\u91cc\u6240\u6db5\u76d6\u7684\u5185\u5bb9\uff0c\u5982\u679c\u4f60\u662f\u65b0\u624b\uff0c\u90a3\u5c31\u8ba9\u8fd9\u505a\u4e3a\u4e00\u4e2a\u7b80\u5355\u7684\u6982\u5ff5\u4ecb\u7ecd\u5427\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u9762\u7684\u6559\u7a0b\u4e2d\u66f4\u6df1\u5165\u5730\u8ba8\u8bba\u65b9\u6cd5\u548c\u7c7b\u3002<\/p>\n<h3>\u4ee3\u7801\u793a\u4f8b<\/h3>\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u4f7f\u7528\u4e86\u4e00\u4e9b\u9009\u9879\uff0c\u5168\u90e8\u7684\u4e8b\u4ef6\u548c\u4e0a\u9762\u63cf\u8ff0\u7684\u5168\u90e8\u65b9\u6cd5\u3002\u5e0c\u671b\u8fd9\u4e2a\u4ee3\u7801\u6709\u81ea\u89e3\u91ca\u6027\uff0c\u4e0d\u591a\u6ce8\u91ca\u91cc\u53c8\u66f4\u591a\u8bf4\u660e\u3002\u8bb0\u4f4f\uff0c\u4e0b\u9762\u6240\u6709\u7684\u4e8b\u60c5\u90fd\u5fc5\u9700\u5728domready\u4e8b\u4ef6\u91cc\u9762\u3002<\/p>\n<p><pre lang=\"javascript\">\nvar sortableListsArray = $$('#numberlist, #letterlist');\nvar sortableLists = new Sortables(sortableListsArray, {\n        \/\/ \u5f53\u6211\u79fb\u52a8\u7684\u65f6\u5019\uff0c\u590d\u5236\u4e00\u4e2a\u526f\u672c\u8ddf\u968f\u9f20\u6807\u79fb\u52a8\n    clone: true,\n        \/\/ \u5b9a\u4e49\u62d6\u52a8\u63a7\u5236\u5668\uff08\u67c4\uff0c\u628a\u624b\uff09\u7684css\u7c7b\u540d\n    handle: '.handle',\n        \/\/ \u5728\u62d6\u52a8\u4e4b\u540e\uff0c\u5141\u8bb8\u4f60\u4f7f\u7528\u7279\u6548\u8ba9\u5b83\u56de\u5230\u67d0\u4e2a\u4f4d\u7f6e\n    revert: {\n        \/\/ \u63a5\u53d7Fx\u9009\u9879\n        duration: 50\n    },\n        \/\/ \u51b3\u5b9a\u62d6\u52a8\u5143\u7d20\u7684\u4e0d\u900f\u660e\u5ea6\uff0c\u800c\u4e0d\u662f\u8ddf\u968f\u9f20\u6807\u7684\u526f\u672c\n    opacity: .5,\n \n    onStart: function(el){\n        \/\/ \u4f20\u9012\u7684\u662f\u4f60\u6b63\u5728\u62d6\u52a8\u7684\u5143\u7d20\n        $('start_ind').highlight('#F3F865');\n        el.highlight('#F3F865');\n    },\n    onSort: function(el) {\n        \/\/ \u4f20\u9012\u7684\u662f\u4f60\u6b63\u5728\u62d6\u52a8\u7684\u5143\u7d20\n        $('sort_ind').highlight('#F3F865');\n    },\n    onComplete: function(el) {\n        \/\/ \u4f20\u9012\u7684\u662f\u4f60\u6b63\u5728\u62d6\u52a8\u7684\u5143\u7d20\n        $('complete_ind').highlight('#F3F865');\n        var listOne = sortableLists.serialize(0);\n        var listTwo = sortableLists.serialize(1);\n        $('numberOrder').set('text', listOne).highlight('#F3F865');    ;\n        $('letterOrder').set('text', listTwo).highlight('#F3F865');    ;\n    }\n}).detach(); \/\/ \u7981\u7528\u63a7\u5236\u5668\uff0c\u56e0\u6b64\u4f60\u5fc5\u9700\u70b9\u51fb\u6309\u94ae\u624d\u80fd\u8ba9\u5b83\u4eec\u53ef\u4ee5\u62d6\u52a8\n \nvar addListoSort = $('addListTest');\n \n$('addListButton').addEvent('click', function(){\n        sortableLists.addLists(addListoSort);\n});\n \n$('removeListButton').addEvent('click', function(){\n    sortableLists.removeLists(addListoSort);\n});\n \n$('enable_handles').addEvent('click', function(){\n    sortableLists.attach();\n});\n \n$('disable_handles').addEvent('click', function(){\n    sortableLists.detach();\n});\n \nvar itemOne = $('one');\n \n$('add_item').addEvent('click', function(){\n    sortableLists.addItems(itemOne);\n});\n \n$('remove_item').addEvent('click', function(){\n    sortableLists.removeItems(itemOne);\n});\n<\/pre>\n<\/p>\n<p>\u63a7\u5236\u5668\u9ed8\u8ba4\u662f\u6ca1\u6709\u542f\u7528\u7684\uff08\u4ed4\u7ec6\u770b\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\uff09\u3002\u8981\u5f00\u59cb\u62d6\u52a8\u6392\u5e8f\uff0c\u4f60\u9700\u8981\u70b9\u51fb\u201c\u542f\u7528\u6392\u5e8f\u201d\u6309\u94ae\u3002<\/p>\n<p>\n<script type=\"text\/javascript\">\nwindow.addEvent('domready', function() {\nvar sortableListsArray = $$('#listA, #listB');\nvar sortableLists = new Sortables(sortableListsArray);<\/p>\n<p>var sortableListsArray = $$('#numberlist, #letterlist');\nvar sortableLists = new Sortables(sortableListsArray, {\n\tclone: true,\n\thandle: '.handle', \n\trevert: {\n\t    \/\/accepts Fx options\n\t\tduration: 50\n\t},\n\topacity: .5,\n\tonStart: function(el){\n\t\t\/\/passes element you are dragging\n\t\t$('start_ind').highlight('#F3F865');\t\n\t\tel.highlight('#F3F865');\t\n\t},\n\tonSort: function(el) {\n\t\t\/\/passes element you are dragging\n\t\t$('sort_ind').highlight('#F3F865');\n\t},\n\tonComplete: function(el) {\n\t\t\/\/passes element you are dragging\n\t\t$('complete_ind').highlight('#F3F865');\t\n\t\tvar listOne = sortableLists.serialize(0);\n\t\tvar listTwo = sortableLists.serialize(1);\n\t\t$('numberOrder').set('text', listOne).highlight('#F3F865');\t;\n\t\t$('letterOrder').set('text', listTwo).highlight('#F3F865');\t;\n\t}\n}).detach(); \/\/disables the handles, so you must push the button to get them going<\/p>\n<p>var addListoSort = $('addListTest');<\/p>\n<p>$('addListButton').addEvent('click', function(){\n\tsortableLists.addLists(addListoSort);\n});<\/p>\n<p>$('removeListButton').addEvent('click', function(){\n\tsortableLists.removeLists(addListoSort);\n});<\/p>\n<p>$('enable_handles').addEvent('click', function(){\n\tsortableLists.attach();\n});<\/p>\n<p>$('disable_handles').addEvent('click', function(){\n\tsortableLists.detach();\n});<\/p>\n<p>var itemOne = $('one');<\/p>\n<p>$('add_item').addEvent('click', function(){\n\tsortableLists.addItems(itemOne);\n});<\/p>\n<p>$('remove_item').addEvent('click', function(){\n\tsortableLists.removeItems(itemOne);\n});<\/p>\n<p>});\n<\/script><\/p>\n<style type=\"text\/css\">\n.sortlists{width:200px;list-style-type:none;min-height:30px;}\n.sortlists li{padding:5px;background-color:#333;color:white;font-size:23px;border-bottom:1px solid white;margin:0 !important}\n.sortlists li span{height:25px;width:20px;background-color:#666;display:block;float:left;margin-right:10px;cursor:pointer;}\n.sortlists li span span{height:25px;width:20px;}\n.ind{width:200px;padding:10px;background-color:#33CCCC;border-bottom:1px solid white;} \n.order{padding:10px;width:auto;}\n<\/style>\n<div id=\"start_ind\" class=\"ind\">onStart<\/p>\n<\/div>\n<div id=\"sort_ind\" class=\"ind\">onSort<\/p>\n<\/div>\n<div id=\"complete_ind\" class=\"ind\">onComplete<\/p>\n<\/div>\n<p>\n  <input type=\"button\" id=\"enable_handles\" value=\"\u542f\u7528\u6392\u5e8f\" \/><br \/> <br \/>\n  <input type=\"button\" id=\"disable_handles\" value=\"\u7981\u7528\u6392\u5e8f\" \/>\n<\/p>\n<p>\n  <input type=\"button\" id=\"add_item\" value=\"\u6dfb\u52a0\u9879\u4e00\" \/><br \/> <br \/>\n  <input type=\"button\" id=\"remove_item\" value=\"\u79fb\u9664\u9879\u4e00\" \/>\n<\/p>\n<div id=\"numberOrder\" class=\"order\">Top List Order<\/div>\n<ul id=\"numberlist\" class=\"sortlists\">\n<li id=\"one\"><span class=\"handle\"><\/span>1<\/li>\n<li id=\"two\"><span class=\"handle\"><\/span>2<\/li>\n<li id=\"three\"><span class=\"handle\"><\/span>3<\/li>\n<li id=\"four\"><span class=\"handle\"><\/span>4<\/li>\n<li id=\"five\"><span class=\"handle\"><\/span>5<\/li>\n<li id=\"six\"><span class=\"handle\"><\/span>6<\/li>\n<li id=\"seven\"><span class=\"handle\"><\/span>7<\/li>\n<\/ul>\n<div id=\"letterOrder\" class=\"order\">Bottom List Order<\/div>\n<ul id=\"letterlist\" class=\"sortlists\">\n<li id=\"lettera\"><span class=\"handle\"><\/span>A<\/li>\n<li id=\"letterb\"><span class=\"handle\"><\/span>B<\/li>\n<li id=\"letterc\"><span class=\"handle\"><\/span>C<\/li>\n<li id=\"letterd\"><span class=\"handle\"><\/span>D<\/li>\n<li id=\"lettere\"><span class=\"handle\"><\/span>E<\/li>\n<li id=\"letterf\"><span class=\"handle\"><\/span>F<\/li>\n<li id=\"letterg\"><span class=\"handle\"><\/span>G<\/li>\n<\/ul>\n<p>\n  <input type=\"button\" id=\"addListButton\" value=\"\u6dfb\u52a0\u5217\u8868\" \/><br \/> <br \/>\n  <input type=\"button\" id=\"removeListButton\" value=\"\u79fb\u9664\u5217\u8868\" \/>\n<\/p>\n<ul id=\"addListTest\" class=\"sortlists\">\n<li id=\"\"><span class=\"handle\"><\/span>add A<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add B<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add C<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add D<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add E<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add F<\/li>\n<li id=\"\"><span class=\"handle\"><\/span>add G<\/li>\n<\/ul>\n<h3>\u66f4\u591a\u5b66\u4e60<\/h3>\n<p>\u53c2\u8003\u9605\u8bfb\u6587\u6863\u4e2d<a href=\"http:\/\/docs.mootools.net\/Plugins\/Sortables\" target=\"_blank\" title=\"\u6709\u5173sortable\u7684\u8fd9\u4e00\u8282\">\u6709\u5173sortable\u7684\u8fd9\u4e00\u8282<\/a>\u3002<\/p>\n<p><b><a href=\"http:\/\/www.consideropen.com\/downloads\/30days_of_moo\/mootorial_day16_sortables.zip\" target=\"_blank\" title=\"\u4e0b\u8f7d\u4e00\u4e2a\u5305\u542b\u4f60\u5f00\u59cb\u6240\u9700\u8981\u7684\u6240\u6709\u4e1c\u897f\u7684zip\u5305\">\u4e0b\u8f7d\u4e00\u4e2a\u5305\u542b\u4f60\u5f00\u59cb\u6240\u9700\u8981\u7684\u6240\u6709\u4e1c\u897f\u7684zip\u5305<\/a><\/b><\/p>\n<p>\u5305\u62ecMooTools 1.2\u7684\u6838\u5fc3\u5e93\u548c\u6269\u5c55\uff08\u66f4\u591a\uff09\u5e93\uff0c\u4e0a\u9762\u7684\u793a\u4f8b\uff0c\u4e00\u4e2a\u5916\u90e8\u7684JavaScript\u6587\u4ef6\uff0c\u4e00\u4e2a\u7b80\u5355\u7684HTML\u9875\u9762\u548c\u4e00\u4e2aCSS\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MooTools 1.2\u7684\u6574\u7406\u6392\u5e8f\u7c7bSortables \u539f\u6587\u5730\u5740\uff1a30 Days of Mootools 1.2 Tutorials &#8211; Day 16 &#8211; Sortables and Intro to Methods \u8bf7\u5c0a\u91cd\u4e2a\u4eba\u52b3\u52a8\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttp:\/\/fdream.net\uff0c\u8bd1\u8005\uff1aFdream \u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u51c6\u5907\u597d\u5f00\u59cb\u8fd9\u4e00\u8bb2\uff0c\u8bf7\u53c2\u8003\u8fd9\u4e00\u7cfb\u5217\u7684\u6559\u7a0b\uff0c\u8fd9\u91cc\u662f\u300aMooTools 1.2\u7cfb\u5217\u6559\u7a0b\u76ee\u5f55\u300b\u3002 \u4ece\u4eca\u5929\u5f00\u59cb\uff0c\u6211\u4eec\u5c06\u5f00\u59cb\u8bb2\u89e3\u201c\u66f4\u591a\u201d\uff08more\uff09\u5e93\u91cc\u9762\u7684\u66f4\u591a\u63d2\u4ef6\u3002Sortables\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u63d2\u4ef6\uff0c\u80fd\u591f\u771f\u6b63\u5730\u6269\u5927\u4f60\u7684\u7528\u6237\u754c\u9762\u8bbe\u8ba1\u7684\u9009\u62e9\u9762\u3002Sortables\u7c7b\u8fd8\u63d0\u4f9b\u4e86\u5305\u62ec\u4e00\u4e2a\u540d\u53eb\u201cserialize\u201d\u7684\u4f18\u79c0\u65b9\u6cd5\uff0c\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u4f60\u989d\u53ef\u4ee5\u628a\u8fd9\u4e9b\u5143\u7d20\u7684id\u4f5c\u4e3a\u6570\u7ec4\u8f93\u51fa\u2014\u2014\u5bf9\u4e8e\u670d\u52a1\u5668\u7aef\u7684\u5f00\u53d1\u975e\u5e38\u6709\u7528\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u770b\u770b\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6392\u5e8f\u9879\u96c6\u5408\uff0c\u8fd8\u6709\u4e00\u5b9a\u8981\u770b\u4e00\u4e0b\u6700\u540e\u7684\u6f14\u793a\u5b9e\u4f8b\u3002 \u57fa\u672c\u77e5\u8bc6 \u521b\u5efa\u4e00\u4e2a\u65b0\u7684Sortable\u5bf9\u8c61 \u9996\u5148\uff0c\u6211\u4eec\u8981\u628a\u6211\u4eec\u8981\u6392\u5e8f\u7684\u5143\u7d20\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002\u5bf9\u4e8eSortables\u6765\u8bf4\uff0c\u5982\u679c\u4f60\u60f3\u8981\u591a\u4e2a\u5217\u8868\u4e4b\u95f4\u7684\u5143\u7d20\u80fd\u591f\u5728\u76f8\u4e92\u4e4b\u95f4\u62d6\u62fd\uff0c\u4f60\u9700\u8981\u628a\u8fd9\u4e9b\u5143\u7d20\u5168\u90e8\u90fd\u653e\u5728\u4e00\u4e2a\u6570\u7ec4\u4e2d\uff0c\u5c31\u50cf\u8fd9\u6837\uff1a var sortableListsArray = $$(&#8216;#listA, #listB&#8217;); \u8fd9\u6837\u5c31\u53ef\u4ee5\u628a\u4e24\u4e2aul\u7684id\u653e\u5230\u4e00\u4e2a\u6570\u7ec4\u91cc\u9762\u4e86\u3002\u6211\u4eec\u73b0\u5728\u5c31\u53ef\u4ee5\u4ece\u8fd9\u4e2a\u6570\u7ec4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684sortable\u5bf9\u8c61\u4e86\uff1a var sortableLists = new Sortables(sortableListsArray); \u6211\u4eec\u5047\u8bbe\u4f7f\u7528\u7684\u662f\u4e0b\u9762\u7684HTML\uff1a &lt;ul id=&quot;listA&quot;&gt; &lt;li&gt;Item A1&lt;\/li&gt; &lt;li&gt;Item A2&lt;\/li&gt; &lt;li&gt;Item A3&lt;\/li&gt; &lt;li&gt;Item A4&lt;\/li&gt; &lt;\/ul&gt; &lt;ul id=&quot;listB&quot;&gt; &lt;li&gt;Item B1&lt;\/li&gt; &lt;li&gt;Item B2&lt;\/li &lt;li&gt;Item B3&lt;\/li&gt; &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[120,104,328,123],"class_list":["post-628","post","type-post","status-publish","format-standard","hentry","category-coding","tag-AJAX","tag-JavaScript","tag-mootools","tag-123"],"views":13713,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=628"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/628\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}