{"id":7624,"date":"2018-05-31T00:09:32","date_gmt":"2018-05-30T16:09:32","guid":{"rendered":"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7624"},"modified":"2018-05-31T00:18:02","modified_gmt":"2018-05-30T16:18:02","slug":"click-page-popup-text-tips","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/05\/click-page-popup-text-tips\/","title":{"rendered":"\u5c0ftips: \u70b9\u51fb\u9875\u9762\u51fa\u73b0\u5bcc\u5f3a\u3001\u6c11\u4e3b\u8fd9\u7c7b\u6587\u5b57\u52a8\u753b\u6548\u679c"},"content":{"rendered":"<p>by <a href=\"http:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7624\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=7624<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u8981\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\u3002<\/p>\n<h3>\u4e00\u3001\u6587\u5b57\u52a8\u753b\u6548\u679c\u9884\u89c8<\/h3>\n<p><strong>\u70b9\u51fb\u672c\u9875\u9762\u4efb\u610f\u4f4d\u7f6e\u5373\u53ef\uff01<\/strong>\u56e0\u4e3a\u52a8\u753b\u6548\u679c\u7528\u7684\u662fCSS3 <code>animation<\/code>\uff0c\u56e0\u6b64\uff0cIE9\u53ca\u5176\u4ee5\u4e0b\u6d4f\u89c8\u5668\u65e0\u6548\u679c\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201805\/2018-05-31_001704.png\" width=\"267\" height=\"295\" alt=\"\u5bcc\u5f3a\u6c11\u4e3b\u6587\u5b57\u6548\u679c\u622a\u56fe\" class=\"imgpad\" \/><\/p>\n<style>.text-popup{animation:textPopup 1s;color:red;user-select:none;white-space:nowrap;position:absolute;z-index:99}@keyframes textPopup{0%,100%{opacity:0}5%{opacity:1}100%{transform:translateY(-50px)}}<\/style>\n<p><script>var fnTextPopup=function(a,c){var e={container:document.documentElement,className:\"text-popup\"};var f={};c=c||{};for(var d in e){if(typeof c[d]!=\"undefined\"){f[d]=c[d]}else{f[d]=e[d]}}if(!a||!a.length){return}var b=0;f.container.addEventListener(\"click\",function(i){var h=i.pageX,j=i.pageY;var g=document.createElement(\"span\");g.className=f.className;this.appendChild(g);if(a[b]){g.innerHTML=a[b]}else{b=0;g.innerHTML=a[0]}g.addEventListener(\"animationend\",function(){f.container.removeChild(g)});g.style.left=(h-g.clientWidth\/2)+\"px\";g.style.top=(j-g.clientHeight)+\"px\";b++})};fnTextPopup([\"\u5bcc\u5f3a\",\"\u6c11\u4e3b\",\"\u6587\u660e\",\"\u548c\u8c10\",\"\u81ea\u7531\",\"\u5e73\u7b49\",\"\u516c\u6b63\",\"\u6cd5\u6cbb\",\"\u7231\u56fd\",\"\u656c\u4e1a\",\"\u8bda\u4fe1\",\"\u53cb\u5584\"]);<\/script><\/p>\n<h3>\u4e8c\u3001\u5982\u4f55\u5728\u81ea\u5df1\u7f51\u7ad9\u4e0a\u6dfb\u52a0\u7c7b\u4f3c\u6548\u679c\uff1f<\/h3>\n<h4>1. \u590d\u5236\u5e76\u7c98\u8d34\u4e0b\u9762\u7684\u5185\u8054CSS\u4ee3\u7801\u5230\u9875\u9762\u4efb\u610f\u4f4d\u7f6e<\/h4>\n<pre>&lt;style&gt;\n.text-popup {\n    animation: textPopup 1s;\n    color: red;\n    user-select: none;\n    white-space: nowrap;\n    position: absolute;\n    z-index: 99;\n}\n@keyframes textPopup {\n    0%, 100% {\n        opacity: 0;\n    }\n    5% {\n        opacity: 1;\n    }\n    100% {\n        transform: translateY(-50px);    \n    }\n}\n&lt;\/style&gt;<\/pre>\n<h4>2. \u590d\u5236\u4e0b\u9762\u7684\u5185\u8054JS\u4ee3\u7801\u5230\u9875\u9762\u4efb\u610f\u4f4d\u7f6e<\/h4>\n<pre>&lt;script&gt;\nvar fnTextPopup = function (arr, options) {\n    <span style=\"color:green;\">\/\/ arr\u53c2\u6570\u662f\u5fc5\u987b\u7684<\/span>\n    if (!arr || !arr.length) {\n        return;    \n    }\n    <span style=\"color:green;\">\/\/ \u4e3b\u903b\u8f91<\/span>\n    var index = 0;\n    document.documentElement.addEventListener('click', function (event) {\n        var x = event.pageX, y = event.pageY;\n        var eleText = document.createElement('span');\n        eleText.className = 'text-popup';\n        this.appendChild(eleText);\n        if (arr[index]) {\n            eleText.innerHTML = arr[index];\n        } else {\n            index = 0;\n            eleText.innerHTML = arr[0];\n        }\n        <span style=\"color:green;\">\/\/ \u52a8\u753b\u7ed3\u675f\u540e\u5220\u9664\u81ea\u5df1<\/span>\n        eleText.addEventListener('animationend', function () {\n            eleText.parentNode.removeChild(eleText);\n        });\n        <span style=\"color:green;\">\/\/ \u4f4d\u7f6e<\/span>\n        eleText.style.left = (x - eleText.clientWidth \/ 2) + 'px';\n        eleText.style.top = (y - eleText.clientHeight) + 'px';\n        <span style=\"color:green;\">\/\/ index\u9012\u589e<\/span>\n        index++;\n    });    \n};\n\nfnTextPopup(['\u5bcc\u5f3a', '\u6c11\u4e3b', '\u6587\u660e', '\u548c\u8c10', '\u81ea\u7531', '\u5e73\u7b49', '\u516c\u6b63', '\u6cd5\u6cbb', '\u7231\u56fd', '\u656c\u4e1a', '\u8bda\u4fe1', '\u53cb\u5584']);\n&lt;\/script&gt;<\/pre>\n<p>\u5c31\u6709\u6548\u679c\u4e86\uff01<\/p>\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u628aCSS\u548cJS\u4ee3\u7801\u7247\u6bb5\u5206\u522b\u5185\u5d4c\u5230\u81ea\u5df1\u7684CSS\u6587\u4ef6\u548cJS\u6587\u4ef6\u4e2d\u3002<\/p>\n<h3>\u4e09\u3001\u70b9\u51fb\u9875\u9762\u51fa\u73b0\u6587\u5b57\u52a8\u753b\u6548\u679c\u5b9e\u73b0\u539f\u7406<\/h3>\n<p>DOM\u65f6\u95f4\u7684<code>event<\/code>\u5bf9\u8c61\u4e2d\u6709\u4e2a<code>pageX<\/code>\u548c<code>pageY<\/code>\u53ef\u4ee5\u83b7\u53d6\u5230\u70b9\u51fb\u4e8b\u4ef6\u53d1\u751f\u65f6\u5019\u4e8b\u4ef6\u53d1\u751f\u6e90\u76f8\u5bf9\u4e8e\u9875\u9762\u5de6\u4e0a\u89d2\u7684\u6c34\u5e73\u8ddd\u79bb\u548c\u5782\u76f4\u8ddd\u79bb\u3002\u5bf9\u4e8e\u9f20\u6807\u70b9\u51fb\u4e8b\u4ef6\uff0c\u5219\u5bf9\u5e94\u9f20\u6807\u76f8\u5bf9\u4e8e\u9875\u9762\u5de6\u4e0a\u89d2\u7684\u8ddd\u79bb\uff0c\u56e0\u6b64\uff0c\u6211\u4eec\u53ea\u8981\u628a\u6587\u5b57\u5185\u5bb9\u5b9a\u4f4d\u5230\u8fd9\u4e2a\u70b9\u51fb\u4f4d\u7f6e\u504f\u4e0a\u4e00\u70b9\u4f4d\u7f6e\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u7136\u540e\uff0c\u914d\u5408CSS3 <code>animation<\/code>\uff0c\u5199\u4e00\u4e2a\u5f80\u4e0a\u6de1\u51fa\u6548\u679c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u5f53\u6587\u5b57\u5143\u7d20\u63d2\u5165\u5230\u9875\u9762\u7684\u65f6\u5019\uff0c\u52a8\u753b\u4f1a\u81ea\u52a8\u6267\u884c\u3002<\/p>\n<p>\u4e3a\u4e86\u9632\u6b62\u6587\u5b57\u5143\u7d20\u4e0d\u65ad\u521b\u5efa\uff0c\u5360\u7528\u4e0d\u5fc5\u8981\u7684\u8d44\u6e90\uff0c\u6211\u4eec\u53ef\u4ee5\u501f\u52a9<code>animationend<\/code>\u4e8b\u4ef6\u5b9e\u73b0\u52a8\u753b\u7ed3\u675f\u7684\u65f6\u5019\u81ea\u52a8\u5220\u9664\u521b\u5efa\u7684\u6587\u5b57\u5143\u7d20\u3002<\/p>\n<pre>ele.addEventListener('animationend', function () {\n    ele.parentNode.removeChild(ele);\n});<\/pre>\n<h3>\u56db\u3001\u8bed\u6cd5\u548c\u53c2\u6570<\/h3>\n<p>\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>fnTextPopup(arr);<\/pre>\n<p>\u5176\u4e2d\uff0c<code>arr<\/code>\u8868\u793a\u4f9d\u6b21\u8981\u663e\u793a\u7684\u6587\u5b57\u5185\u5bb9\u6570\u7ec4\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u6211\u4eec\u5e0c\u671b\u70b9\u51fb\u9875\u9762\u663e\u793a\u7684\u4e0d\u662f\u6838\u5fc3\u793e\u4f1a\u4e3b\u4e49\u4ef7\u503c\u89c2\uff0c\u800c\u662f\u60f3\u4e3a\u81ea\u5df1\u559c\u6b22\u5076\u50cf\u52a0\u6cb9\uff0c\u53ef\u4ee5\u8fd9\u6837\uff1a<\/p>\n<pre>fnTextPopup(['\u8521\u5f90\u5764\u6211\u7231\u4f60', '\u8303\u4e1e\u4e1e\u4f60\u6700\u68d2', '\u8bf7pick\u6768\u8d85\u8d8a', '\u738b\u83ca\u52a0\u6cb9', '\u5434\u5ba3\u4eea\u4f60\u6700\u7f8e']);<\/pre>\n<p>\u5982\u679c\u60f3\u8981\u4fee\u6539tips\u6587\u5b57\u7684\u989c\u8272\uff0c\u5b57\u4f53\u7b49\u6837\u5f0f\u6548\u679c\uff0c\u4fee\u6539CSS\u4ee3\u7801\u4e2d<code>.text-popup<\/code>\u7c7b\u540d\u5bf9\u5e94\u7684CSS\u5c5e\u6027\u5373\u53ef\uff01<\/p>\n<h3>\u4e94\u3001\u7ed3\u675f\u8bed<\/h3>\n<p>\u5982\u679c\u60f3\u8981\u52a0\u5165IE8\u6d4f\u89c8\u5668\uff0c\u53ef\u4ee5\u6309\u7167\u4e0a\u9762\u5b9e\u73b0\u903b\u8f91\uff0c\u6539\u6210jQuery\u7684\u8bed\u6cd5\uff0c\u7136\u540e\uff0c\u52a8\u753b\u53ef\u4ee5\u4f7f\u7528jQuery\u7684<code>animate()<\/code>\u65b9\u6cd5\uff0c\u8fd9\u91cc\u4e0d\u5c55\u793a\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u79fb\u52a8\u7aef\u6ca1\u6d4b\u8bd5\uff0c\u5982\u679c\u6ca1\u6548\u679c\uff0c\u8bd5\u8bd5<code>document.documentElement<\/code>\u6539\u6210<code>document.body<\/code>\u3002<\/p>\n<p>\u672c\u6587\u51e0\u4e4e\u6ca1\u6709\u6df1\u5ea6\uff0c\u4f46\u662f\uff0c\u6709\u4ef7\u503c\uff0c\u4e00\u4e9b\u4ee3\u7801\u521a\u5165\u95e8\u7684\u5c0f\u670b\u53cb\u5c31\u9700\u8981\u8fd9\u4e9b\u4e1c\u897f\uff0c\u8282\u7ea6\u4e86\u522b\u4eba\u7684\u65f6\u95f4\uff0c\u5e2e\u52a9\u4e86\u522b\u4eba\u5b9e\u73b0\u529f\u80fd\uff0c\u662f\u4ef6\u6709\u4ef7\u503c\u7684\u4e8b\u60c5\uff0c\u56e0\u6b64\uff0c\u503c\u5f97\u82b1\u65f6\u95f4\u8bb0\u5f55\u4e0b\u6765\u3002\u800c\u4e14\uff0c\u4ee5\u540e\uff0c\u8bf4\u4e0d\u5b9a\u81ea\u5df1\u4e5f\u8981\u7528\u5230\u8fd9\u4e2a\u6548\u679c\uff0c\u4e5f\u53ef\u4ee5\u8282\u7ea6\u81ea\u5df1\u7684\u65f6\u95f4\uff0c\u4e00\u4e3e\u4e24\u5f97\u3002<\/p>\n<p>\u5199\u4f5c\u8fd9\u4e8b\u5427\uff0c\u4e5f\u968f\u7f18\uff0c\u522b\u603b\u60f3\u7740\u5e2e\u5230\u6240\u6709\u4eba\uff0c\u6ca1\u5fc5\u8981\u90a3\u4e48\u529f\u5229\uff0c\u53ea\u8981\u4e0d\u8bef\u4eba\uff0c\u6709\u4ef7\u503c\uff0c\u6211\u89c9\u5f97\u90fd\u662f\u503c\u5f97\u9f13\u52b1\u7684\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/image.zhangxinxu.com\/image\/blog\/201611\/14.png\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"http:\/\/www.zhangxinxu.com\/wordpress\/?p=7624\">http:\/\/www.zhangxinxu.com\/wordpress\/?p=7624<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5b9e\u73b0\u70b9\u51fb\u9875\u9762\u51fa\u73b0\u5bcc\u5f3a\u3001\u6c11\u4e3b\u8fd9\u7c7b\u6587\u5b57\u52a8\u753b\u6548\u679c\uff1f\u5f88\u7b80\u5355\uff0c\u590d\u5236\u672c\u6587\u63d0\u4f9b\u7684\u6e90\u4ee3\u7801\uff0c\u6548\u679c\u7acb\u5373\u5c31\u51fa\u73b0\u4e86\u3002\u5feb\u8fdb\u6765\u770b\u770b\u600e\u4e48\u5b9e\u73b0\u7684\u5427\uff1f<\/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":[705,531,811,161,870,9],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7624"}],"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=7624"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7624\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=7624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=7624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=7624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}