{"id":1576,"date":"2011-04-07T18:27:05","date_gmt":"2011-04-07T10:27:05","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576"},"modified":"2018-01-01T23:23:07","modified_gmt":"2018-01-01T15:23:07","slug":"%e5%b0%8ftip%ef%bc%9a%e8%bf%94%e5%9b%9e%e9%a1%b6%e9%83%a8%e5%8a%9f%e8%83%bd%e7%9a%84js%e5%ae%9e%e7%8e%b0jquerymootools","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2011\/04\/%e5%b0%8ftip%ef%bc%9a%e8%bf%94%e5%9b%9e%e9%a1%b6%e9%83%a8%e5%8a%9f%e8%83%bd%e7%9a%84js%e5%ae%9e%e7%8e%b0jquerymootools\/","title":{"rendered":"\u4eff\u65b0\u6d6a\u5fae\u535a\u8fd4\u56de\u9876\u90e8\u7684js\u5b9e\u73b0(jQuery\/MooTools)"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a><br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576<\/a><\/p>\n<h3>\u4e00\u3001\u5f15\u8a00<\/h3>\n<p>\u5728web\u9875\u9762\u4e2d\uff0c\u5982\u679c\u9875\u9762\u8f83\u9ad8\uff0c\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u5feb\u901f\u5730\u8fd4\u56de\u9876\u90e8\uff0c\u90fd\u4f1a\u6dfb\u52a0\u4e00\u4e2a\u8fd4\u56de\u9876\u90e8\u6309\u94ae\u3002\u4f8b\u5982\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201104\/2011-04-07_170554.png\" title=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" width=\"152\" height=\"155\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201104\/2011-04-07_171638.png\" title=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" width=\"189\" height=\"92\" \/><br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201104\/2011-04-07_171857.png\" title=\"\u5404\u7f51\u7ad9\u8fd4\u56de\u9876\u90e8\u529f\u80fd\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" width=\"164\" height=\"126\" \/><\/p>\n<p>\u5176\u4e2d\u6dd8\u5b9d\u7f51\u7684\u662f\u8981\u6eda\u52a8\u6761\u7684\u6eda\u52a8\u8ddd\u79bb\u5927\u4e8e\u67d0\u4e00\u6bb5\u8ddd\u79bb\u624d\u663e\u793a\u8fd4\u56de\u9876\u90e8\u6309\u94ae\uff1b\u4eba\u4eba\u7f51\u7684\u8fd4\u56de\u9876\u90e8\u76f4\u63a5\u5728\u5e95\u90e8\u7684\u5de5\u5177\u6761\u4e0a\uff1b\u65b0\u6d6a\u5fae\u535a\u7684\u8fd4\u56de\u9876\u90e8\u5728\u6eda\u52a8\u9ad8\u5ea6\u5927\u4e8e0\u7684\u65f6\u5019\u663e\u793a\uff0c\u4e14\u8fd4\u56de\u9876\u90e8\u7684\u6548\u679c\u662f\u5e73\u6ed1\u52a8\u753b\u6548\u679c\u3002\u672c\u6587\u7684\u5b9e\u73b0\u5c31\u662f\u7c7b\u4f3c\u4e8e\u65b0\u6d6a\u5fae\u535a\u7684\u8fd9\u79cd\u6548\u679c\u3002<span class=\"s\">\/\/zxx:\u65b0\u6d6a\u5fae\u535a\u4eca\u5929\u542f\u7528\u65b0\u57df\u540dweibo.com\u4e86<\/span><\/p>\n<h3>\u4e8c\u3001jQuery\u4e0b\u7684\u8fd4\u56de\u9876\u90e8\u529f\u80fd<\/h3>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201104\/back-to-top-jquery.html\">jQuery\u4e0b\u7684\u8fd4\u56de\u9876\u90e8demo<\/a><\/p>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5982\u679c\u9875\u9762\u6709\u6eda\u52a8\u9ad8\u5ea6\uff0c\u53f3\u4e0b\u89d2\u5c31\u4f1a\u6709\u4e00\u4e2a\u542b\u6709\u201c\u8fd4\u56de\u9876\u90e8\u201d\u5b57\u6837\u7684\u9ed1\u8272\u80cc\u666f\u534a\u900f\u660e\u7684\u5c0f\u6761\u6761\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/>\n<img loading=\"lazy\" decoding=\"async\" alt=\"demo\u9875\u9762\u6548\u679c\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201104\/2011-04-07_173010.png\" title=\"demo\u9875\u9762\u6548\u679c\u622a\u56fe \u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\" class=\"alignnone\" width=\"154\" height=\"145\" \/><\/p>\n<p>\u70b9\u51fb\u8fd9\u91cc\u201c\u8fd4\u56de\u9876\u90e8\u201d\u5b57\u6837\u7684\u6309\u94ae\u540e\uff0c\u9875\u9762\u5c31\u50cf\u662f\u62b9\u4e86\u6da6\u6ed1\u5242\u4e00\u6837\uff0c\u500f\u5730\u4e00\u58f0\u5c31\u6ed1\u5230\u9876\u90e8\u4e86\uff0c\u540c\u65f6\uff0c\u8be5\u70b9\u51fb\u6309\u94ae\u4e5f\u73a9\u8d77\u4e86\u8eb2\u732b\u732b &#8211; \u4e0d\u89c1\u4e86\u3002<\/p>\n<p>\u5b9e\u73b0\u7684\u539f\u7406\u561b\uff0c\u6069\u2026\u2026\u4f30\u8ba1\u9c9c\u6709\u4eba\u5173\u5fc3\uff0c\u6240\u4ee5\u6211\u4e5f\u61d2\u5f97\u6d6a\u8d39\u53e3\u6c34\u4e86\uff0c\u76f4\u63a5\u4e0a\u4ee3\u7801\u3002<\/p>\n<p>\u65e0\u8bba\u662f\u8fd9\u91cc\u7684jQuery\u5b9e\u73b0\u8fd8\u662fMooTools\u5b9e\u73b0\uff0c\u4e0b\u9762\u7684CSS\u4ee3\u7801\u90fd\u662f\u4e00\u81f4\u7684\uff0c\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>.backToTop {\n    display: none;\n    width: 18px;\n    line-height: 1.2;\n    padding: 5px 0;\n    background-color: #000;\n    color: #fff;\n    font-size: 12px;\n    text-align: center;\n    position: fixed;\n    _position: absolute;\n    right: 10px;\n    bottom: 100px;\n    _bottom: \"auto\";\n    cursor: pointer;\n    opacity: .6;\n    filter: Alpha(opacity=60);\n}<\/pre>\n<\/div>\n<p>js\u76f8\u5173\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>(function() {\n    var $backToTopTxt = \"\u8fd4\u56de\u9876\u90e8\", $backToTopEle = $('&lt;div class=\"backToTop\">&lt;\/div>').appendTo($(\"body\"))\n        .text($backToTopTxt).attr(\"title\", $backToTopTxt).click(function() {\n            $(\"html, body\").animate({ scrollTop: 0 }, 120);\n    }), $backToTopFun = function() {\n        var st = $(document).scrollTop(), winh = $(window).height();\n        (st > 0)? $backToTopEle.show(): $backToTopEle.hide();    \n        \/\/IE6\u4e0b\u7684\u5b9a\u4f4d\n        if (!window.XMLHttpRequest) {\n            $backToTopEle.css(\"top\", st + winh - 166);    \n        }\n    };\n    $(window).bind(\"scroll\", $backToTopFun);\n    $(function() { $backToTopFun(); });\n})();<\/pre>\n<\/div>\n<p>\u5be5\u5be5\u5341\u51e0\u884c\u4ee3\u7801\u5c31\u5b9e\u73b0\u4e86\u5168\u90e8\u7684\u4ea4\u4e92\u7ec6\u8282\u4e86\u3002\u60a8\u53ef\u4ee5\u5c06\u4e0a\u9762\u4ee3\u7801\u76f4\u63a5\u62f7\u8d1d\u5230\u60a8\u7684JavaScript\u6587\u4ef6\u4e2d\uff0c\u9875\u9762\u5c31\u6709\u6548\u679c\u5566\uff01\u5bf9\u4e86\uff0c\u8bf7\u4f7f\u7528jQuery 1.4+\u3002<\/p>\n<div class=\"hidden\"><em>\u5982\u679c\u60a8\u770b\u5230\u4e0b\u9762\u7684\u6587\u5b57\uff0c\u53ef\u80fd\u662f\u7531\u4e8e\u5728\u5176\u4ed6\u7f51\u7ad9\u6216\u662fRSS\u4e2d\u9605\u8bfb\u672c\u6587\uff0c\u672c\u6587\u539f\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576<\/a>\uff0c\u672c\u6587\u4f5c\u8005\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed<\/a>\uff0c\u6765\u81ea\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b\uff0c\u8bbf\u95ee\u539f\u51fa\u5904\u66f4\u591a\u4f18\u79c0\u6280\u672f\u6587\u7ae0\u3002<\/em><\/div>\n<h3>\u4e09\u3001MooTools\u4e0b\u8fd4\u56de\u9876\u90e8\u529f\u80fd\u5b9e\u73b0<\/h3>\n<p>\u60a8\u53ef\u4ee5\u72e0\u72e0\u5730\u70b9\u51fb\u8fd9\u91cc\uff1a<a class=\"a_link\" target=\"_blank\" href=\"http:\/\/www.zhangxinxu.com\/study\/201104\/back-to-top-mootools.html\">MooTools\u4e0b\u7684\u8fd4\u56de\u9876\u90e8demo<\/a><\/p>\n<p>demo\u9875\u9762\u7684\u6548\u679c\u4e0e\u4e0a\u9762jQuery demo\u4e0b\u6548\u679c\u57fa\u672c\u4e00\u81f4\u3002<\/p>\n<p>\u4ee3\u7801\u90e8\u5206\u3002CSS\u4ee3\u7801\u5b8c\u5168\u540c\u4e0a\u3002JS\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<div class=\"zxx_code\">\n<pre>(function() {\n    var $backToTopTxt = \"\u8fd4\u56de\u9876\u90e8\", $backToTopEle = new Element(\"div\", {\n        \"class\": \"backToTop\",\n        title: $backToTopTxt    \n    }).set(\"text\", $backToTopTxt).addEvent(\"click\", function() {\n        var st = document.getScroll().y, speed = st \/ 6;\n        var funScroll = function() {\n            st -= speed;\n            if (st <= 0) { st = 0; }\n            window.scrollTo(0, st);\n            if (st > 0) { setTimeout(funScroll, 20); }\n        };\n        funScroll();\n    }).inject(document.body), $backToTopFun = function() {\n        var st = document.getScroll().y, winh = window.getSize().y;\n        (st > 0)? $backToTopEle.setStyle(\"display\", \"block\"): $backToTopEle.setStyle(\"display\", \"none\");    \n        \/\/IE6\u4e0b\u7684\u5b9a\u4f4d\n        if (!window.XMLHttpRequest) {\n            $backToTopEle.setStyle(\"top\", st + winh - 166);    \n        }\n    };\n    window.addEvents({\n        scroll: $backToTopFun,\n        domready: $backToTopFun\n    });\n})();<\/pre>\n<\/div>\n<p>\u76f4\u63a5\u62f7\u8d1d\u4e0a\u9762\u7684\u4ee3\u7801\u5728\u60a8\u7684JS\u4ee3\u7801\u4e2d\u5c31\u8f7b\u677e\u5b9e\u73b0\u6548\u679c\u5566\u3002<\/p>\n<p>MooTools\u7684\u52a8\u753b\u65b9\u6cd5<code>Fx<\/code>\u4e0d\u652f\u6301\u6eda\u52a8\uff0c\u8981\u5b9e\u73b0\u6eda\u52a8\u6761\u7684\u5e73\u6ed1\u6eda\u52a8\u6548\u679c\u9700\u8981\u4f7f\u7528<code>Fx.Scroll<\/code>\u63d2\u4ef6\u3002\u4f46\u662f\uff0c\u663e\u7136\uff0c \u8fd9\u91cc\u7684\u7b80\u5355\u529f\u80fd\u6ca1\u6709\u5fc5\u8981\u518d\u4f7f\u7528\u989d\u5916\u7684\u63d2\u4ef6\uff0c\u6240\u4ee5\u76f4\u63a5\u8bbe\u7f6e\u4e86\u4e2a\u5b9a\u65f6\u5668\u5b9e\u73b0\u4e86\u5e73\u6ed1\u6eda\u52a8\u6548\u679c\u3002<\/p>\n<p><strong>\u6ce8\uff1a<\/strong>demo\u9875\u9762\u4e2d\u7684\u7f8e\u5973\u56fe\u7247\u4f5c\u7528\u662f\u6491\u5f00\u9875\u9762\u9ad8\u5ea6\u4f7f\u4ea7\u751f\u6eda\u52a8\u6761\u3002<\/p>\n<h3>\u56db\u3001\u7ed3\u8bed<\/h3>\n<p>\u5176\u5b9e\u5b9e\u73b0\u9875\u9762\u8fd4\u56de\u9876\u90e8\u6548\u679c\u6700\u7b80\u5355\u7684\u5c31\u662fa\u6807\u7b7e\u7136\u540ehref\u5c5e\u6027\u503c\u76f4\u63a5\u5c31\u662f#\u951a\u70b9\u5c31ok\u4e86\u3002\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u4f1a\u5728url\u5730\u5740\u540e\u9762\u4ea7\u751f\u4e00\u4e2a&#8221;#&#8221;\u3002\u5173\u4e8e\u951a\u70b9\u76f8\u5173\u7684\u5185\u5bb9\u60a8\u53ef\u4ee5\u53c2\u89c1\u6211\u4e4b\u524d\u7684\u201c<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=958\">\u5173\u4e8e\u951a\u70b9\u8df3\u8f6c\u53cajQuery\u4e0b\u76f8\u5173\u64cd\u4f5c\u4e0e\u63d2\u4ef6<\/a>\u201d\u4e00\u6587\u3002<\/p>\n<p>\u672c\u6587\u7b97\u662f\u4e2a\u5b9e\u7528\u5c0f\u6280\u672f\uff0c\u5185\u5bb9\u4e0d\u591a\uff0c\u5e0c\u671b\u80fd\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002\u611f\u8c22\u9605\u8bfb\u3002<\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u6765\u81ea<a href=\"http:\/\/www.zhangxinxu.com\/\">\u5f20\u946b\u65ed-\u946b\u7a7a\u95f4-\u946b\u751f\u6d3b<\/a>[<a href=\"http:\/\/www.zhangxinxu.com\/\">http:\/\/www.zhangxinxu.com<\/a>]<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=1576<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728web\u9875\u9762\u4e2d\uff0c\u5982\u679c\u9875\u9762\u8f83\u9ad8\uff0c\u4e3a\u4e86\u65b9\u4fbf\u7528\u6237\u5feb\u901f\u5730\u8fd4\u56de\u9876\u90e8\uff0c\u90fd\u4f1a\u6dfb\u52a0\u4e00\u4e2a\u8fd4\u56de\u9876\u90e8\u6309\u94ae\u3002\u672c\u6587\u5c31\u5c06\u7b80\u5355\u5c55\u793a\u4e0b\u8fd9\u79cd\u6548\u679c\uff0c\u672c\u6587\u7684\u6548\u679c\u53c2\u7167\u65b0\u6d6a\u5fae\u535a\u7684\u8fd4\u56de\u9876\u90e8\u6548\u679c\uff0c\u5c55\u793a\u4e86\u5728jQuery\u5e93\u548cMooTools\u5e93\u4e0b\u7684\u5b9e\u73b0\u3002\u672c\u6587\u63d0\u4f9b\u5fc5\u8981\u7684demo\u9875\u9762\u548c\u6e90\u4ee3\u7801\u5c55\u793a\u3002\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[180],"tags":[14,448,181,165,585,444],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/1576"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1576"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/1576\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}