{"id":1862,"date":"2017-08-28T11:44:14","date_gmt":"2017-08-28T03:44:14","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1862"},"modified":"2017-08-28T11:44:14","modified_gmt":"2017-08-28T03:44:14","slug":"javascript%e5%ae%9e%e7%8e%b0canvas%e5%9b%be%e7%89%87%e6%97%8b%e8%bd%ac","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1862","title":{"rendered":"Javascript\u5b9e\u73b0canvas\u56fe\u7247\u65cb\u8f6c"},"content":{"rendered":"<p>\n\t\u8fd9\u4e24\u5929\u6211\u628a\u6211\u7684\u535a\u5ba2\uff1a<a href=\"https:\/\/www.xttblog.com\" name=\"\u4e1a\u4f59\u8349xttblog\" target=\"_blank\" title=\"\u4e1a\u4f59\u8349xttblog\">\u4e1a\u4f59\u8349xttblog<\/a>\u5347\u7ea7\u4e86<a href=\"https:\/\/baike.baidu.com\/item\/https\" name=\"https\" target=\"_blank\" title=\"https\">https<\/a>\uff0c\u66f4\u65b0\u7684\u6587\u7ae0\u53ef\u80fd\u4e0d\u662f\u5f88\u591a\u3002\u4eca\u5929\u4e3a\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u4f7f\u7528Javascript\u5b9e\u73b0canvas\u56fe\u7247\u65cb\u8f6c\u3002\n<\/p>\n<p>\n\t\u8bba\u575b\u4e2d\u6709\u5f88\u591a\u4eba\u95ee\u6211\u5173\u4e8e Canvas \u95ee\u9898\uff0cCanvas\u73b0\u5728\u7814\u7a76\u7684\u4eba\u5f88\u591a\uff0c\u4f46\u662f\u57fa\u4e8eCanvas\u7684\u5e94\u7528\u76ee\u524d\u8fd8\u4e0d\u662f\u5f88\u591a\uff0c\u4e3b\u8981\u662f\u56fd\u5185\u7684 ie \u4f4e\u7248\u672c\u6d4f\u89c8\u5668\u7528\u6237\u592a\u591a\u3002\u4f46\u662f\u8fd9\u4e9b\u90fd\u6beb\u4e0d\u5f71\u54cd\u6211\u4eec\u961f HTML5 \u7684\u70ed\u60c5\u3002\n<\/p>\n<p>\n\t\u4e00\u822c\u5728\u6ce8\u518c\u9875\u9762\uff0c\u6211\u4eec\u4e0a\u4f20\u56fe\u7247\u65f6\uff0c\u4f1a\u8fdb\u884c\u4e00\u4e9b\u56fe\u7247\u526a\u8d34\uff0c\u65cb\u8f6c\u7b49\u529f\u80fd\u3002\u4f7f\u7528HTML5\u7684canvas\u6807\u7b7e\u53ef\u5bf9\u56fe\u7247\u8fdb\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u5bf9\u4e8eie6\uff0c7\uff0c8\u4e0d\u652f\u6301HTML5\u7684\u6d4f\u89c8\u5668\uff0c\u6211\u4eec\u4f7f\u7528IE\u7279\u6709\u7684\u6ee4\u955c\u6548\u679c\u6765\u5b9e\u73b0\u3002\n<\/p>\n<p>\n\t\u4e0b\u9762\u662fdemo\u7684\u8fd0\u884c\u6548\u679c\uff1a\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Canvas \u7f16\u8f91\u56fe\u7247\" src=\"http:\/\/img.bbs.csdn.net\/upload\/201708\/28\/1503890798_763266.png\" style=\"width: 664px;height: 359px\" \/>\n<\/p>\n<p>\n\tHTML \u4ee3\u7801\u5f88\u7b80\u5355\uff0c\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:xml;\">\r\n&lt;div id=&quot;tool&quot;&gt; \r\n     &lt;a href=&quot;#&quot; id=&quot;arr_left&quot; onclick=&quot;rotate(&#039;myimg&#039;,&#039;left&#039;)&quot;&gt;\u5411\u5de6&lt;\/a&gt; \r\n     &lt;a href=&quot;#&quot; id=&quot;arr_right&quot; onclick=&quot;rotate(&#039;myimg&#039;,&#039;right&#039;)&quot;&gt;\u5411\u53f3&lt;\/a&gt; \r\n&lt;\/div&gt; \r\n&lt;!-- \u64cd\u4f5c\u83dc\u5355\uff0c\u4e1a\u4f59\u8349\uff1awww.xttblog.com --&gt;\r\n&lt;div id=&quot;img&quot;&gt; \r\n     &lt;img src=&quot;demo.jpg&quot; width=&quot;460&quot; height=&quot;305&quot; alt=&quot;&quot; id=&quot;myimg&quot; \/&gt; \r\n&lt;\/div&gt; <\/pre>\n<p>\n\t\u6700\u91cd\u8981\u7684\u65cb\u8f6c\u65b9\u6cd5rotate\u7684\u5b9e\u73b0\u4ee3\u7801\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:jscript;\">\r\nfunction rotate(obj,arr){ \r\n    var img = document.getElementById(obj); \r\n    if(!img || !arr) return false; \r\n    var n = img.getAttribute(&#039;step&#039;); \r\n    if(n== null) n=0; \r\n    if(arr==&#039;left&#039;){ \r\n        (n==0)? n=3:n--; \r\n    }else if(arr==&#039;right&#039;){ \r\n        (n==3)? n=0:n++; \r\n    } \r\n    img.setAttribute(&#039;step&#039;,n); \r\n    ... \/\/\u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n\t\/\/\u5bf9IE\u6d4f\u89c8\u5668\u4f7f\u7528\u6ee4\u955c\u65cb\u8f6c \r\n    if(document.all) { \r\n        img.style.filter = &#039;progid:DXImageTransform.Microsoft.BasicImage(rotation=&#039;+ n +&#039;)&#039;; \r\n    \/\/ \u5bf9\u73b0\u4ee3\u6d4f\u89c8\u5668\u5199\u5165HTML5\u7684\u5143\u7d20\u8fdb\u884c\u65cb\u8f6c\uff1a canvas \r\n    }else{ \r\n        ... \r\n    } \r\n} <\/pre>\n<p>\n\t\u5bf9\u4e8eIE\u6d4f\u89c8\u5668\u6211\u4eec\u4f7f\u7528\u4e86\u6ee4\u955c\u529f\u80fd\u3002\u521b\u5efacanvas\u5143\u7d20\u5bf9\u8c61\uff0c\u5e76\u5c06\u56fe\u7247\u8d4b\u4e88canvas\u5bf9\u8c61\uff0c\u5f53\u53d8\u91cfn\u5904\u4e8e\u4e0d\u540c\u7684\u72b6\u6001\uff08\u4e0a\u4e0b\u5de6\u53f3\u56db\u4e2a\u65b9\u5411\uff09\u65f6\uff0c\u4f7f\u7528canvas\u91cd\u65b0\u5bf9\u56fe\u50cf\u8fdb\u884c\u7ed8\u5236\u3002\n<\/p>\n<p>\n\t\u5f53\u7136\uff0c\u56fe\u7247\u7684\u65cb\u8f6c\u6548\u679c\u5b9e\u73b0\u8fd8\u6709\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u7ed5\u5f00html5\uff0c\u9488\u5bf9\u5404\u4e0d\u540c\u7684\u6d4f\u89c8\u5668\uff0c\u6bd4\u5982firefox\u4e0b\u9762\u53ef\u4ee5\u7528-moz-transform: rotate(); webkit\u53ef\u4ee5\u7528-webkit-transform: rotate(); \u4f46\u8fd9\u5e76\u4e0d\u5982html5\u7684canvas\u5b9e\u73b0\u7684\u6548\u679c\u597d\u3002\n<\/p>\n<p>\n\t\u6e90\u4ee3\u7801\u5df2\u5171\u4eab\u5728github\uff1a<a href=\"https:\/\/github.com\/xmt1139057136\/imgRotate\" name=\"imgRotate\" target=\"_blank\" title=\"imgRotate\">https:\/\/github.com\/xmt1139057136\/imgRotate<\/a><\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1862\">Javascript\u5b9e\u73b0canvas\u56fe\u7247\u65cb\u8f6c<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e24\u5929\u6211\u628a\u6211\u7684\u535a\u5ba2\uff1a\u4e1a\u4f59\u8349xttblog\u5347\u7ea7\u4e86https\uff0c\u66f4\u65b0\u7684\u6587\u7ae0\u53ef\u80fd\u4e0d\u662f\u5f88\u591a\u3002\u4eca\u5929\u4e3a\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u4f7f\u7528Jav [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[31,115,334,1465],"class_list":["post-1862","post","type-post","status-publish","format-standard","hentry","category-html5","tag-canvas","tag-transform","tag-1465"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1862"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1862\/revisions"}],"predecessor-version":[{"id":1863,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1862\/revisions\/1863"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}