{"id":5061,"date":"2024-09-30T18:01:01","date_gmt":"2024-09-30T10:01:01","guid":{"rendered":""},"modified":"2024-09-30T18:01:01","modified_gmt":"2024-09-30T10:01:01","slug":"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801","status":"publish","type":"post","link":"https:\/\/mushiming.com\/5061.html","title":{"rendered":"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u535a\u5ba2\u94fe\u63a5<\/strong>\uff1a<\/p>\n

\n

https:\/\/www.cnblogs.com\/steamed-twisted-roll\/p\/13408245.html<\/p>\n<\/blockquote>\n

\u6548\u679c\u5982\u56fe,\u56fe\u7247\u53ef\u4ee5\u8ddf\u968f\u9f20\u6807\u79fb\u52a8,\u65cb\u8f6c,\u62c9\u4f38,\u4ee3\u7801\u5728\u8c37\u6b4c\u6d4f\u89c8\u5668\u548cIE11\u9a8c\u8bc1\u4e86,\u5176\u4ed6\u6d4f\u89c8\u5668\u6ca1\u8bd5\u8fc7
\u672c\u535a\u5ba2\u6e90\u7801: https:\/\/github.com\/shengbid\/vue-demo \u628a\u8fd9\u4e2a\u529f\u80fd\u653e\u5728vue\u9879\u76ee\u91cc\u4e86, \u8fd9\u4e2a\u9879\u76ee\u91cc\u4f1a\u628a\u5e73\u65f6\u535a\u5ba2\u5199\u7684\u4e00\u4e9b\u529f\u80fd\u7684\u4ee3\u7801\u90fd\u653e\u5728\u91cc\u9762,\u6709\u9700\u8981\u53ef\u4ee5\u4e0b\u8f7d\u770b\u770b,\u6709\u5e2e\u52a9\u7684\u8bdd\u70b9\u4e2astar\u54c8\"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801<\/p>\n

\u6211\u4e3b\u8981\u8bb2\u4e00\u4e0b\u5b9e\u73b0\u601d\u8def,
\u9996\u5148\u662f\u79fb\u52a8,\u8fd9\u4e2a\u6bd4\u8f83\u7b80\u5355
\u8fd9\u91cc\u6211\u7528\u7684\u662f\u9f20\u6807\u4e8b\u4ef6\u7684pageX,pageY,\u56e0\u4e3a\u8fd9\u4e2a\u83b7\u53d6\u7684\u662f\u9f20\u6807\u8ddd\u6587\u6863\u5de6\u4e0a\u89d2\u7684\u5750\u6807,\u4e0d\u53d7\u6eda\u52a8\u6761\u5f71\u54cd<\/p>\n

\u753b\u4e00\u5f20\u56fe\u6765\u6f14\u793a
\u5982\u56fe.\u7eff\u8272\u662f\u9f20\u6807\u79fb\u52a8\u4f4d\u7f6e,pageX,pageY\u662f\u9f20\u6807\u6309\u4e0b\u7684\u4f4d\u7f6e,pageX1,pageY1\u662f\u9f20\u6807\u79fb\u52a8\u505c\u6b62\u65f6\u7684\u4f4d\u7f6e
\"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801
pageX\u662f\u7531\u56fe\u7247\u7684left + \u9f20\u6807\u5230\u56fe\u7247\u5de6\u8fb9\u7684\u8ddd\u79bb\u7ec4\u6210,\u4e5f\u8bb8\u8fd8\u6709\u5176\u4ed6\u7684padding,margin\u4e4b\u7c7b\u7684,\u4f46\u662f\u4e0d\u5f71\u54cd,\u7edf\u7edf\u90fd\u7b97\u6210c
pageX = left + c
c = pageX - left
\u8981\u6c42\u7b2c\u4e8c\u6b21\u7684left\u503c,\u53ea\u9700\u8981\u7528pageX1 - c\u5c31\u53ef\u4ee5
left1 = pageX1 - c<\/p>\n

\u518d\u628a\u8ba1\u7b97\u51fa\u7684left1\u8d4b\u503c\u7ed9\u5b9a\u4f4d\u5143\u7d20,top\u662f\u540c\u6837\u7684\u8ba1\u7b97
\u56e0\u4e3a\u6211\u7684\u56fe\u7247\u662f\u5305\u5728\u4e00\u4e2adiv\u5143\u7d20\u91cc,\u5b9a\u4f4d\u7ed9\u5c31\u8fd9\u4e2adiv\u8d4b\u503c<\/p>\n

\u4ee3\u7801\u5b9e\u73b0<\/p>\n

\/\/ \u5143\u7d20\u79fb\u52a8<\/span> var<\/span> moveMouse =<\/span> false<\/span>;<\/span> $<\/span>(<\/span>'.img'<\/span>)<\/span>.<\/span>mousedown<\/span>(<\/span>function<\/span> (<\/span>e)<\/span> { \n   <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> e.<\/span>stopPropagation<\/span>(<\/span>)<\/span> moveMouse =<\/span> true<\/span> var<\/span> dis =<\/span> { \n   <\/span> X<\/span>:<\/span> e.<\/span>pageX -<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>position<\/span>(<\/span>)<\/span>.<\/span>left,<\/span> Y<\/span>:<\/span> e.<\/span>pageY -<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>position<\/span>(<\/span>)<\/span>.<\/span>top }<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mousemove'<\/span>,<\/span> function<\/span> (<\/span>event)<\/span> { \n   <\/span> event.<\/span>preventDefault<\/span>(<\/span>)<\/span> event.<\/span>stopPropagation<\/span>(<\/span>)<\/span> if<\/span> (<\/span>moveMouse)<\/span> { \n   <\/span> var<\/span> end =<\/span> { \n   <\/span>}<\/span> end.<\/span>X<\/span> =<\/span> event.<\/span>pageX -<\/span> dis.<\/span>X<\/span> end.<\/span>Y<\/span> =<\/span> event.<\/span>pageY -<\/span> dis.<\/span>Y<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>css<\/span>(<\/span>{ \n   <\/span> 'left'<\/span>:<\/span> end.<\/span>X<\/span>,<\/span> 'top'<\/span>:<\/span> end.<\/span>Y<\/span> }<\/span>)<\/span> }<\/span> }<\/span>)<\/span> }<\/span>)<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mouseup'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> moveMouse =<\/span> false<\/span> }<\/span>)<\/span>;<\/span> <\/code><\/pre>\n

\u8fd9\u6837\u5c31\u5b9e\u73b0\u79fb\u52a8\u529f\u80fd\u4e86<\/p>\n

\u518d\u6765\u5b9e\u73b0\u5143\u7d20\u7684\u65cb\u8f6c\u62c9\u4f38\u529f\u80fd
\u62c9\u4f38\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u5143\u7d20\u7684width\u548cheight\u5b9e\u73b0,\u4e5f\u53ef\u4ee5\u901a\u8fc7transform\u7684scale\u5b9e\u73b0
\u8fd9\u91cc\u6d89\u53ca\u4e00\u4e2a\u95ee\u9898,\u65cb\u8f6c\u7684\u65f6\u5019\u4ee5\u56fe\u7247\u5de6\u4e0a\u89d2\u4e3a\u65cb\u8f6c\u70b9\u8fd8\u662f\u4ee5\u56fe\u7247\u4e2d\u5fc3\u70b9\u4e3a\u65cb\u8f6c\u70b9,transform\u7684rotate\u9ed8\u8ba4\u662f\u4ee5\u5143\u7d20\u7684\u4e2d\u5fc3\u70b9\u4e3a\u65cb\u8f6c\u70b9.\u800cwidth\u548cheight\u7684\u6539\u53d8\u662f\u4ee5\u5143\u7d20\u5de6\u4e0a\u89d2\u4e3a\u57fa\u70b9,\u8fd9\u91cc\u6211\u4eec\u8981\u505a\u7684\u529f\u80fd\u662f\u8fb9\u65cb\u8f6c\u8fb9\u6539\u53d8\u56fe\u7247\u5927\u5c0f,\u90a3\u4e48\u7edf\u4e00\u90fd\u4ee5\u56fe\u7247\u4e2d\u5fc3\u70b9\u4e3a\u57fa\u70b9.\u8fd9\u6837\u7684\u8bdd\u7528width\u548cheight\u6765\u5b9e\u73b0\u653e\u5927\u7f29\u5c0f\u529f\u80fd\u5c31\u4e0d\u65b9\u4fbf\u4e86,\u6240\u4ee5\u8fd8\u662f\u4f7f\u7528scale\u6765\u5b9e\u73b0<\/p>\n

\u5148\u770b\u65cb\u8f6c\u7684\u5b9e\u73b0,\u4ee5\u8fd9\u5f20\u56fe\u8bf4\u660e,\u9996\u5148\u9700\u8981\u786e\u5b9a\u4e2d\u5fc3\u70b9,\u8fd8\u6709\u7b2c\u4e00\u6b21\u9f20\u6807\u6309\u4e0b\u7684\u70b9pointB,\u4ee5\u540e\u6bcf\u6b21\u65cb\u8f6c\u90fd\u662f\u6c42BA,CA\u7684\u5939\u89d2,\u4e5f\u5c31\u662fcosA
\"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801 \u4ee3\u7801\u5b9e\u73b0<\/p>\n

var<\/span> pointA =<\/span> { \n   <\/span> \/\/ \u5143\u7d20\u4e2d\u5fc3\u70b9 \u5143\u7d201\/2\u81ea\u8eab\u5bbd\u9ad8 + \u5143\u7d20\u7684\u5b9a\u4f4d<\/span> X<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>width<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>left,<\/span> Y<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>height<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>top }<\/span>;<\/span> console.<\/span>log<\/span>(<\/span>pointA)<\/span> var<\/span> pointB =<\/span> { \n   <\/span>}<\/span>;<\/span> var<\/span> pointC =<\/span> { \n   <\/span>}<\/span>;<\/span> \/\/ A,B,C\u5206\u522b\u4ee3\u8868\u4e2d\u5fc3\u70b9\uff0c\u8d77\u59cb\u70b9\uff0c\u7ed3\u675f\u70b9\u5750\u6807<\/span> \/\/ \u8fd9\u91cc\u901a\u8fc7\u9f20\u6807\u7684\u79fb\u52a8\u83b7\u53d6\u8d77\u59cb\u70b9\u548c\u7ed3\u675f\u70b9<\/span> var<\/span> typeMouse =<\/span> false<\/span>;<\/span> var<\/span> allA =<\/span> 0<\/span>;<\/span> \/\/ \u5b58\u653e\u9f20\u6807\u65cb\u8f6c\u603b\u5171\u7684\u5ea6\u6570<\/span> var<\/span> count =<\/span> 0<\/span>;<\/span> \/\/ \u5143\u7d20\u8ddf\u968f\u9f20\u6807\u79fb\u52a8\u65cb\u8f6c<\/span> $<\/span>(<\/span>\".rotate\"<\/span>)<\/span>.<\/span>on<\/span>(<\/span>'mousedown'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> e.<\/span>stopPropagation<\/span>(<\/span>)<\/span> typeMouse =<\/span> true<\/span>;<\/span> \/\/\u83b7\u53d6\u8d77\u59cb\u70b9\u5750\u6807<\/span> if<\/span> (<\/span>count <<\/span> 1<\/span>)<\/span> { \n   <\/span> \/\/ \u4ee5\u9f20\u6807\u7b2c\u4e00\u6b21\u843d\u4e0b\u7684\u70b9\u4e3a\u8d77\u70b9<\/span> pointB.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointB.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> count++<\/span> }<\/span> console.<\/span>log<\/span>(<\/span>5<\/span>,<\/span> pointA,<\/span> pointB)<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mousemove'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> if<\/span> (<\/span>typeMouse)<\/span> { \n   <\/span> pointC.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointC.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> \/\/ \u83b7\u53d6\u7ed3\u675f\u70b9\u5750\u6807<\/span> \/\/ \u8ba1\u7b97\u51fa\u65cb\u8f6c\u89d2\u5ea6<\/span> var<\/span> AB<\/span> =<\/span> { \n   <\/span>}<\/span>;<\/span> var<\/span> AC<\/span> =<\/span> { \n   <\/span>}<\/span>;<\/span> AB<\/span>.<\/span>X<\/span> =<\/span> (<\/span>pointB.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span>)<\/span>;<\/span> AB<\/span>.<\/span>Y<\/span> =<\/span> (<\/span>pointB.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span>)<\/span>;<\/span> AC<\/span>.<\/span>X<\/span> =<\/span> (<\/span>pointC.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span>)<\/span>;<\/span> AC<\/span>.<\/span>Y<\/span> =<\/span> (<\/span>pointC.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span>)<\/span>;<\/span> \/\/ \u5206\u522b\u6c42\u51faAB,AC\u7684\u5411\u91cf\u5750\u6807\u8868\u793a<\/span> var<\/span> direct =<\/span> (<\/span>AB<\/span>.<\/span>X<\/span> *<\/span> AC<\/span>.<\/span>Y<\/span>)<\/span> -<\/span> (<\/span>AB<\/span>.<\/span>Y<\/span> *<\/span> AC<\/span>.<\/span>X<\/span>)<\/span>;<\/span> \/\/ AB\u4e0eAC\u53c9\u4e58\u6c42\u51fa\u9006\u65f6\u9488\u8fd8\u662f\u987a\u65f6\u9488\u65cb\u8f6c<\/span> var<\/span> lengthAB =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>X<\/span> -<\/span> pointB.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>Y<\/span> -<\/span> pointB.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>,<\/span> lengthAC =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>X<\/span> -<\/span> pointC.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>Y<\/span> -<\/span> pointC.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>,<\/span> lengthBC =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointB.<\/span>X<\/span> -<\/span> pointC.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointB.<\/span>Y<\/span> -<\/span> pointC.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>;<\/span> var<\/span> cosA =<\/span> (<\/span>Math.<\/span>pow<\/span>(<\/span>lengthAB,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>lengthAC,<\/span> 2<\/span>)<\/span> -<\/span> Math.<\/span>pow<\/span>(<\/span>lengthBC,<\/span> 2<\/span>)<\/span>)<\/span> \/<\/span> (<\/span>2<\/span> *<\/span> lengthAB *<\/span> lengthAC)<\/span>;<\/span> \/\/ \u4f59\u5f26\u5b9a\u7406\u6c42\u51fa\u65cb\u8f6c\u89d2<\/span> var<\/span> angleA =<\/span> Math.<\/span>round<\/span>(<\/span>Math.<\/span>acos<\/span>(<\/span>cosA)<\/span> *<\/span> 180<\/span> \/<\/span> Math.<\/span>PI<\/span>)<\/span>;<\/span> if<\/span> (<\/span>direct <<\/span> 0<\/span>)<\/span> { \n   <\/span> allA =<\/span> -<\/span>angleA;<\/span> \/\/\u53c9\u4e58\u7ed3\u679c\u4e3a\u8d1f\u8868\u793a\u9006\u65f6\u9488\u65cb\u8f6c\uff0c \u9006\u65f6\u9488\u65cb\u8f6c\u51cf\u5ea6\u6570<\/span> }<\/span> else<\/span> { \n   <\/span> allA =<\/span> angleA;<\/span> \/\/\u53c9\u4e58\u7ed3\u679c\u4e3a\u6b63\u8868\u793a\u987a\u65f6\u9488\u65cb\u8f6c\uff0c\u987a\u65f6\u9488\u65cb\u8f6c\u52a0\u5ea6\u6570<\/span> }<\/span> \/\/ console.log(allA)<\/span> $<\/span>(<\/span>'.img-box'<\/span>)<\/span>.<\/span>css<\/span>(<\/span>'transform'<\/span>,<\/span> 'rotate('<\/span>+<\/span>allA+<\/span>'deg)'<\/span>)<\/span> }<\/span> }<\/span>)<\/span>;<\/span> }<\/span>)<\/span>;<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mouseup'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> typeMouse =<\/span> false<\/span>;<\/span> }<\/span>)<\/span>;<\/span> <\/code><\/pre>\n

\u62c9\u4f38\u5b9e\u73b0,\u5982\u56fe,\u5176\u5b9e\u5c31\u662fAC\/AB\u7684\u6bd4\u4f8b,AB\u548cAC\u7684\u957f\u5ea6\u53ef\u4ee5\u767e\u5ea6\u641c\u7d22\u5df2\u77e5\u4e24\u70b9\u5750\u6807\u6c42\u76f4\u7ebf\u8ddd\u79bb\u67e5\u770b\u8ba1\u7b97\u516c\u5f0f,\u8fd9\u91cc\u5c31\u4e0d\u5c55\u5f00\u4e86
\"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801\u4ee3\u7801\u5b9e\u73b0<\/p>\n

\/\/ \u5143\u7d20\u8ddf\u968f\u9f20\u6807\u79fb\u52a8\u62c9\u4f38<\/span> $<\/span>(<\/span>\".rotate, .rotate1\"<\/span>)<\/span>.<\/span>on<\/span>(<\/span>'mousedown'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> e.<\/span>stopPropagation<\/span>(<\/span>)<\/span> typeMouse =<\/span> true<\/span>;<\/span> \/\/\u83b7\u53d6\u8d77\u59cb\u70b9\u5750\u6807<\/span> if<\/span> (<\/span>count <<\/span> 1<\/span>)<\/span> { \n   <\/span> \/\/ \u4ee5\u9f20\u6807\u7b2c\u4e00\u6b21\u843d\u4e0b\u7684\u70b9\u4e3a\u8d77\u70b9<\/span> pointB.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointB.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> count++<\/span> }<\/span> console.<\/span>log<\/span>(<\/span>5<\/span>,<\/span> pointA,<\/span> pointB)<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mousemove'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> if<\/span> (<\/span>typeMouse)<\/span> { \n   <\/span> pointC.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointC.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> \/\/ \u83b7\u53d6\u7ed3\u675f\u70b9\u5750\u6807<\/span> \/\/ \u8ba1\u7b97\u6bcf\u6b21\u79fb\u52a8\u5143\u7d20\u7684\u534a\u5f84\u53d8\u5316,\u7528\u4f5c\u62c9\u4f38<\/span> var<\/span> scalX1 =<\/span> pointB.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span> var<\/span> scalY1 =<\/span> pointB.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span> var<\/span> scalX =<\/span> pointC.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span> var<\/span> scalY =<\/span> pointC.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span> \/\/ \u8ba1\u7b97\u51fa\u62c9\u4f38\u6bd4\u4f8b<\/span> var<\/span> sa =<\/span> Math.<\/span>sqrt<\/span>(<\/span>scalX1 *<\/span> scalX1 +<\/span> scalY1 *<\/span> scalY1)<\/span> var<\/span> ss =<\/span> Math.<\/span>sqrt<\/span>(<\/span>scalX *<\/span> scalX +<\/span> scalY *<\/span> scalY)<\/span> var<\/span> sc =<\/span> ss \/<\/span> sa \/\/ console.log(sc)<\/span> $<\/span>(<\/span>'.img-box'<\/span>)<\/span>.<\/span>css<\/span>(<\/span>'transform'<\/span>,<\/span> 'scale('<\/span>+<\/span>sc+<\/span>')'<\/span>)<\/span> }<\/span> }<\/span>)<\/span>;<\/span> }<\/span>)<\/span>;<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mouseup'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n   <\/span> typeMouse =<\/span> false<\/span>;<\/span> }<\/span>)<\/span>;<\/span> <\/code><\/pre>\n

html\u4ee3\u7801<\/p>\n

 <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>container\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>box\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>img-box\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>flat\"<\/span><\/span>><\/span><\/span>\u7ffb\u8f6c<\/<\/span>div<\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>rotate\"<\/span><\/span>><\/span><\/span>\u65cb\u8f6c<\/<\/span>div<\/span>><\/span><\/span> <<\/span>img<\/span> src<\/span>=<\/span>\"<\/span>https:\/\/ss1.bdstatic.com\/70cFvXSh_Q1YnxGkpoWK1HF6hhy\/it\/u=,&fm=26&gp=0.jpg\"<\/span><\/span> alt<\/span>=<\/span>\"<\/span>\"<\/span><\/span> class<\/span>=<\/span>\"<\/span>img\"<\/span><\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/code><\/pre>\n

HTML\u5143\u7d20\u7684\u5173\u7cfb,\u56fe\u7247\u9700\u8981\u5305\u4e09\u5c42\u7236\u7ea7div. img-box\u5305\u56fe\u7247,\u65cb\u8f6c\u7684\u65f6\u5019\u65cb\u8f6cimg-box.\u56e0\u4e3a\u65cb\u8f6c\u4e4b\u540eleft\u548ctop\u503c\u4f1a\u6539\u53d8,
\u6240\u4ee5\u9700\u8981\u5728\u5305\u4e00\u5c42box,\u79fb\u52a8\u7684\u65f6\u5019\u6539\u53d8left\u548ctop\u5c31\u6539\u53d8box\u7684\u503c.
\u6700\u5916\u5c42\u7684container\u4e3b\u8981\u662f\u4e00\u4e2a\u5b9a\u4f4d,\u91cc\u9762\u7684\u5143\u7d20\u90fd\u662f\u7edd\u5bf9\u5b9a\u4f4d,\u9700\u8981\u4e00\u4e2a\u76f8\u5bf9\u5b9a\u4f4d\u7684\u7236\u5143\u7d20<\/p>\n

\u7136\u540e,\u8fd9\u4e09\u4e2a\u529f\u80fd\u90fd\u5b9e\u73b0\u4e86,\u628a\u4ed6\u4eec\u7ec4\u5408\u5728\u4e00\u8d77,\u9700\u8981\u6ce8\u610f\u4e00\u70b9\u95ee\u9898
\u79fb\u52a8\u7684\u65f6\u5019,\u56fe\u7247\u7684\u4e2d\u5fc3\u70b9\u4e5f\u6539\u53d8\u4e86,\u6240\u4ee5\u6bcf\u6b21\u79fb\u52a8\u540e\u9700\u8981\u91cd\u65b0\u8ba1\u7b97\u56fe\u7247\u7684\u4e2d\u5fc3\u70b9,\u5bf9\u5e94\u7684pointB\u70b9\u4e5f\u9700\u8981\u5bf9\u5e94\u7684\u6539\u53d8<\/p>\n

\u6700\u540e,\u5982\u679c\u4f60\u9700\u8981\u56db\u4e2a\u89d2\u90fd\u53ef\u4ee5\u65cb\u8f6c,\u9700\u8981\u8ba1\u7b97\u51fa\u4e0d\u540c\u65cb\u8f6c\u89d2\u4e4b\u95f4\u7684\u89d2\u5ea6\u5dee
\u5982\u56fe,\u5982\u679c\u7b2c\u4e00\u6b21\u4ee5\u65cb\u8f6c\u533a\u57df1\u4e3a\u8d77\u70b9,\u70b9\u51fb\u65cb\u8f6c\u533a\u57df2\u65f6\u5c31\u9700\u8981\u52a0\u4e0a\u65cb\u8f6c\u533a\u57df1\u4e0e\u65cb\u8f6c\u533a\u57df2\u76f4\u89d2\u7684\u5939\u89d2,\u4e5f\u5c31\u662f2\u500dtanA
\u5982\u679c\u7b2c\u4e8c\u6b21\u65cb\u8f6c\u9009\u7684\u662f\u65cb\u8f6c\u533a\u57df3,\u90a3\u4e48\u5c31\u9700\u8981\u52a0\u4e0a180\u00b0.\u8fd9\u662f\u987a\u65f6\u9488\u65b9\u5411,\u5982\u679c\u53cd\u8fc7\u6765\u9006\u65f6\u9488\u65b9\u5411\u5c31\u662f\u51cf\u53bb\u5ea6\u6570\u5dee
\"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801
\u5b8c\u6574\u4ee3\u7801<\/p>\n

<!DOCTYPE html><\/span> <<\/span>html<\/span> lang<\/span>=<\/span>\"<\/span>en\"<\/span><\/span>><\/span><\/span> <<\/span>head<\/span>><\/span><\/span> <<\/span>meta<\/span> charset<\/span>=<\/span>\"<\/span>UTF-8\"<\/span><\/span>><\/span><\/span> <<\/span>meta<\/span> name<\/span>=<\/span>\"<\/span>viewport\"<\/span><\/span> content<\/span>=<\/span>\"<\/span>width=device-width, initial-scale=1.0\"<\/span><\/span>><\/span><\/span> <<\/span>title<\/span>><\/span><\/span>Document<\/<\/span>title<\/span>><\/span><\/span> <\/<\/span>head<\/span>><\/span><\/span> <<\/span>style<\/span>><\/span><\/span> html, body<\/span> { \n    <\/span> margin<\/span>:<\/span> 0;<\/span> font-size<\/span>:<\/span> 14px;<\/span> }<\/span> .container<\/span> { \n    <\/span> \/* padding: 20px; border: 1px solid sienna; *\/<\/span> position<\/span>:<\/span> relative;<\/span> }<\/span> .box<\/span> { \n    <\/span> position<\/span>:<\/span> absolute;<\/span> left<\/span>:<\/span> 200px;<\/span> top<\/span>:<\/span> 100px;<\/span> width<\/span>:<\/span> 400px;<\/span> height<\/span>:<\/span> 400px;<\/span> color<\/span>:<\/span> #fff;<\/span> \/* background-color: rosybrown; *\/<\/span> }<\/span> .img-box<\/span> { \n    <\/span> position<\/span>:<\/span> absolute;<\/span> \/* left: 30px; top: 30px; *\/<\/span> width<\/span>:<\/span> 400px;<\/span> height<\/span>:<\/span> 400px;<\/span> background-color<\/span>:<\/span> sandybrown;<\/span> }<\/span> .flat<\/span> { \n    <\/span> position<\/span>:<\/span> absolute;<\/span> right<\/span>:<\/span> -20px;<\/span> top<\/span>:<\/span> -20px;<\/span> width<\/span>:<\/span> 40px;<\/span> height<\/span>:<\/span> 40px;<\/span> background-color<\/span>:<\/span> seagreen;<\/span> z-index<\/span>:<\/span> 3;<\/span> line-height<\/span>:<\/span> 40px;<\/span> text-align<\/span>:<\/span> center;<\/span> cursor<\/span>:<\/span> default;<\/span> }<\/span> .rotate, .rotate1<\/span> { \n    <\/span> position<\/span>:<\/span> absolute;<\/span> right<\/span>:<\/span> -20px;<\/span> bottom<\/span>:<\/span> -20px;<\/span> width<\/span>:<\/span> 40px;<\/span> height<\/span>:<\/span> 40px;<\/span> background-color<\/span>:<\/span> royalblue;<\/span> z-index<\/span>:<\/span> 3;<\/span> cursor<\/span>:<\/span> se-resize;<\/span> line-height<\/span>:<\/span> 40px;<\/span> text-align<\/span>:<\/span> center;<\/span> }<\/span> .rotate1<\/span> { \n    <\/span> left<\/span>:<\/span> -20px;<\/span> right<\/span>:<\/span> auto;<\/span> }<\/span> .img<\/span> { \n    <\/span> width<\/span>:<\/span> 100%;<\/span> height<\/span>:<\/span> 100%;<\/span> cursor<\/span>:<\/span> move;<\/span> }<\/span> .header<\/span> { \n    <\/span> height<\/span>:<\/span> 50px;<\/span> }<\/span> <\/span><\/<\/span>style<\/span>><\/span><\/span> <<\/span>body<\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>header\"<\/span><\/span>><\/span><\/span> <<\/span>h1<\/span>><\/span><\/span>\u56fe\u5f62\u7f16\u8f91<\/<\/span>h1<\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>container\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>box\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>img-box\"<\/span><\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>flat\"<\/span><\/span>><\/span><\/span>\u7ffb\u8f6c<\/<\/span>div<\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>rotate\"<\/span><\/span>><\/span><\/span>\u65cb\u8f6c<\/<\/span>div<\/span>><\/span><\/span> <<\/span>div<\/span> class<\/span>=<\/span>\"<\/span>rotate1\"<\/span><\/span>><\/span><\/span>\u65cb\u8f6c<\/<\/span>div<\/span>><\/span><\/span> <<\/span>img<\/span> src<\/span>=<\/span>\"<\/span>https:\/\/ss1.bdstatic.com\/70cFvXSh_Q1YnxGkpoWK1HF6hhy\/it\/u=,&fm=26&gp=0.jpg\"<\/span><\/span> alt<\/span>=<\/span>\"<\/span>\"<\/span><\/span> class<\/span>=<\/span>\"<\/span>img\"<\/span><\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/<\/span>div<\/span>><\/span><\/span> <\/<\/span>body<\/span>><\/span><\/span> <!-- <script src=\"http:\/\/code.jquery.com\/jquery-2.1.4.min.js\"><\/script> --><\/span> <<\/span>script<\/span> src<\/span>=<\/span>\"<\/span>.\/jquery-3.1.1.min.js\"<\/span><\/span>><\/span><\/span><\/span><\/<\/span>script<\/span>><\/span><\/span> <<\/span>script<\/span> src<\/span>=<\/span>\"<\/span>.\/common-validate\/index.js\"<\/span><\/span>><\/span><\/span><\/span><\/<\/span>script<\/span>><\/span><\/span> <<\/span>script<\/span>><\/span><\/span> console.<\/span>log<\/span>(<\/span>commonValidate)<\/span> var<\/span> flat =<\/span> -<\/span>1<\/span> \/\/ \u955c\u50cf\u7ffb\u8f6c<\/span> $<\/span>(<\/span>\".flat\"<\/span>)<\/span>.<\/span>click<\/span>(<\/span>function<\/span>(<\/span>)<\/span> { \n    <\/span> $<\/span>(<\/span>\".img\"<\/span>)<\/span>.<\/span>css<\/span>(<\/span>\"transform\"<\/span>,<\/span> \"scaleX(\"<\/span>+<\/span>flat+<\/span>\")\"<\/span>)<\/span> flat =<\/span> -<\/span>flat }<\/span>)<\/span> var<\/span> pointA =<\/span> { \n    <\/span> \/\/ \u5143\u7d20\u4e2d\u5fc3\u70b9 \u5143\u7d201\/2\u81ea\u8eab\u5bbd\u9ad8 + \u5143\u7d20\u7684\u5b9a\u4f4d<\/span> X<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>width<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>left,<\/span> Y<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>height<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>top }<\/span>;<\/span> console.<\/span>log<\/span>(<\/span>pointA,<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>position<\/span>(<\/span>)<\/span>)<\/span> var<\/span> pointB =<\/span> { \n    <\/span>}<\/span>;<\/span> var<\/span> pointC =<\/span> { \n    <\/span>}<\/span>;<\/span> \/\/ A,B,C\u5206\u522b\u4ee3\u8868\u4e2d\u5fc3\u70b9\uff0c\u8d77\u59cb\u70b9\uff0c\u7ed3\u675f\u70b9\u5750\u6807<\/span> \/\/ \u8fd9\u91cc\u901a\u8fc7\u9f20\u6807\u7684\u79fb\u52a8\u83b7\u53d6\u8d77\u59cb\u70b9\u548c\u7ed3\u675f\u70b9<\/span> var<\/span> typeMouse =<\/span> false<\/span>;<\/span> var<\/span> moveMouse =<\/span> false<\/span>;<\/span> var<\/span> allA =<\/span> 0<\/span>;<\/span> \/\/ \u5b58\u653e\u9f20\u6807\u65cb\u8f6c\u603b\u5171\u7684\u5ea6\u6570<\/span> var<\/span> count =<\/span> 0<\/span>;<\/span> var<\/span> mPointB =<\/span> { \n    <\/span>}<\/span> \/\/ \u79fb\u52a8\u7684B\u70b9\u8ddd\u79bb<\/span> var<\/span> init =<\/span> { \n    <\/span> count:<\/span> 0<\/span> }<\/span> var<\/span> oldTarget =<\/span> { \n    <\/span> target:<\/span> null<\/span>,<\/span> angle:<\/span> 0<\/span> }<\/span> \/\/ \u5143\u7d20\u8ddf\u968f\u9f20\u6807\u79fb\u52a8\u65cb\u8f6c\u62c9\u4f38<\/span> $<\/span>(<\/span>\".rotate, .rotate1\"<\/span>)<\/span>.<\/span>on<\/span>(<\/span>'mousedown'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n    <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> e.<\/span>stopPropagation<\/span>(<\/span>)<\/span> \/\/ \u8ba1\u7b97\u4e24\u4e2a\u65cb\u8f6c\u65b9\u5757\u4e4b\u95f4\u7684\u89d2\u5ea6<\/span> var<\/span> tanA =<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>width<\/span>(<\/span>)<\/span> \/<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>height<\/span>(<\/span>)<\/span> var<\/span> d =<\/span> Math.<\/span>round<\/span>(<\/span>Math.<\/span>atan<\/span>(<\/span>tanA)<\/span> *<\/span> 180<\/span> \/<\/span> Math.<\/span>PI<\/span>)<\/span> if<\/span> (<\/span>oldTarget.<\/span>target &&<\/span> oldTarget.<\/span>target !=<\/span> e.<\/span>currentTarget)<\/span> { \n    <\/span> if<\/span> (<\/span>e.<\/span>currentTarget ==<\/span> $<\/span>(<\/span>'.rotate'<\/span>)<\/span>[<\/span>0<\/span>]<\/span>)<\/span> { \n    <\/span> oldTarget.<\/span>angle =<\/span> 2<\/span> *<\/span> d }<\/span> else<\/span> { \n    <\/span> oldTarget.<\/span>angle =<\/span> -<\/span>2<\/span> *<\/span> d }<\/span> }<\/span> else<\/span> { \n    <\/span> oldTarget.<\/span>angle =<\/span> 0<\/span> }<\/span> typeMouse =<\/span> true<\/span>;<\/span> \/\/\u83b7\u53d6\u8d77\u59cb\u70b9\u5750\u6807<\/span> if<\/span> (<\/span>count <<\/span> 1<\/span>)<\/span> { \n    <\/span> \/\/ \u4ee5\u9f20\u6807\u7b2c\u4e00\u6b21\u843d\u4e0b\u7684\u70b9\u4e3a\u8d77\u70b9<\/span> pointB.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointB.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> init.<\/span>count =<\/span> 0<\/span> oldTarget.<\/span>target =<\/span> e.<\/span>currentTarget count++<\/span> }<\/span> if<\/span> (<\/span>mPointB.<\/span>flag)<\/span> { \n    <\/span> \/\/ \u5982\u679c\u79fb\u52a8\u540e,\u5143\u7d20\u7684B\u70b9\u4e5f\u9700\u8981\u52a0\u4e0a\u5e73\u79fb\u7684\u8ddd\u79bb<\/span> pointB.<\/span>X<\/span> +=<\/span> mPointB.<\/span>X<\/span> pointB.<\/span>Y<\/span> +=<\/span> mPointB.<\/span>Y<\/span> mPointB.<\/span>flag =<\/span> false<\/span> init.<\/span>count =<\/span> 0<\/span> }<\/span> console.<\/span>log<\/span>(<\/span>'pointA'<\/span>,<\/span> pointA,<\/span> 'pointB'<\/span>,<\/span> pointB)<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mousemove'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n    <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> if<\/span> (<\/span>typeMouse)<\/span> { \n    <\/span> pointC.<\/span>X<\/span> =<\/span> e.<\/span>pageX;<\/span> pointC.<\/span>Y<\/span> =<\/span> e.<\/span>pageY;<\/span> \/\/ \u83b7\u53d6\u7ed3\u675f\u70b9\u5750\u6807<\/span> \/\/ \u8ba1\u7b97\u6bcf\u6b21\u79fb\u52a8\u5143\u7d20\u7684\u534a\u5f84\u53d8\u5316,\u7528\u4f5c\u62c9\u4f38<\/span> var<\/span> scalX1 =<\/span> pointB.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span> var<\/span> scalY1 =<\/span> pointB.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span> var<\/span> scalX =<\/span> pointC.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span> var<\/span> scalY =<\/span> pointC.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span> \/\/ \u8ba1\u7b97\u51fa\u65cb\u8f6c\u89d2\u5ea6<\/span> var<\/span> AB<\/span> =<\/span> { \n    <\/span>}<\/span>;<\/span> var<\/span> AC<\/span> =<\/span> { \n    <\/span>}<\/span>;<\/span> AB<\/span>.<\/span>X<\/span> =<\/span> (<\/span>pointB.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span>)<\/span>;<\/span> AB<\/span>.<\/span>Y<\/span> =<\/span> (<\/span>pointB.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span>)<\/span>;<\/span> AC<\/span>.<\/span>X<\/span> =<\/span> (<\/span>pointC.<\/span>X<\/span> -<\/span> pointA.<\/span>X<\/span>)<\/span>;<\/span> AC<\/span>.<\/span>Y<\/span> =<\/span> (<\/span>pointC.<\/span>Y<\/span> -<\/span> pointA.<\/span>Y<\/span>)<\/span>;<\/span> \/\/ \u5206\u522b\u6c42\u51faAB,AC\u7684\u5411\u91cf\u5750\u6807\u8868\u793a<\/span> var<\/span> direct =<\/span> (<\/span>AB<\/span>.<\/span>X<\/span> *<\/span> AC<\/span>.<\/span>Y<\/span>)<\/span> -<\/span> (<\/span>AB<\/span>.<\/span>Y<\/span> *<\/span> AC<\/span>.<\/span>X<\/span>)<\/span>;<\/span> \/\/ AB\u4e0eAC\u53c9\u4e58\u6c42\u51fa\u9006\u65f6\u9488\u8fd8\u662f\u987a\u65f6\u9488\u65cb\u8f6c<\/span> var<\/span> lengthAB =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>X<\/span> -<\/span> pointB.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>Y<\/span> -<\/span> pointB.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>,<\/span> lengthAC =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>X<\/span> -<\/span> pointC.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointA.<\/span>Y<\/span> -<\/span> pointC.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>,<\/span> lengthBC =<\/span> Math.<\/span>sqrt<\/span>(<\/span>Math.<\/span>pow<\/span>(<\/span>pointB.<\/span>X<\/span> -<\/span> pointC.<\/span>X<\/span>,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>pointB.<\/span>Y<\/span> -<\/span> pointC.<\/span>Y<\/span>,<\/span> 2<\/span>)<\/span>)<\/span>;<\/span> var<\/span> cosA =<\/span> (<\/span>Math.<\/span>pow<\/span>(<\/span>lengthAB,<\/span> 2<\/span>)<\/span> +<\/span> Math.<\/span>pow<\/span>(<\/span>lengthAC,<\/span> 2<\/span>)<\/span> -<\/span> Math.<\/span>pow<\/span>(<\/span>lengthBC,<\/span> 2<\/span>)<\/span>)<\/span> \/<\/span> (<\/span>2<\/span> *<\/span> lengthAB *<\/span> lengthAC)<\/span>;<\/span> \/\/ \u4f59\u5f26\u5b9a\u7406\u6c42\u51fa\u65cb\u8f6c\u89d2<\/span> var<\/span> angleA =<\/span> Math.<\/span>round<\/span>(<\/span>Math.<\/span>acos<\/span>(<\/span>cosA)<\/span> *<\/span> 180<\/span> \/<\/span> Math.<\/span>PI<\/span>)<\/span>;<\/span> if<\/span> (<\/span>direct <<\/span> 0<\/span>)<\/span> { \n    <\/span> allA =<\/span> -<\/span>angleA;<\/span> \/\/\u53c9\u4e58\u7ed3\u679c\u4e3a\u8d1f\u8868\u793a\u9006\u65f6\u9488\u65cb\u8f6c\uff0c \u9006\u65f6\u9488\u65cb\u8f6c\u51cf\u5ea6\u6570<\/span> }<\/span> else<\/span> { \n    <\/span> allA =<\/span> angleA;<\/span> \/\/\u53c9\u4e58\u7ed3\u679c\u4e3a\u6b63\u8868\u793a\u987a\u65f6\u9488\u65cb\u8f6c\uff0c\u987a\u65f6\u9488\u65cb\u8f6c\u52a0\u5ea6\u6570<\/span> }<\/span> allA +=<\/span> oldTarget.<\/span>angle \/\/ $('.img-box').css('transform', 'rotate('+allA+'deg)')<\/span> \/\/ \u8ba1\u7b97\u51fa\u62c9\u4f38\u6bd4\u4f8b<\/span> var<\/span> sa =<\/span> Math.<\/span>sqrt<\/span>(<\/span>scalX1 *<\/span> scalX1 +<\/span> scalY1 *<\/span> scalY1)<\/span> var<\/span> ss =<\/span> Math.<\/span>sqrt<\/span>(<\/span>scalX *<\/span> scalX +<\/span> scalY *<\/span> scalY)<\/span> var<\/span> sc =<\/span> ss \/<\/span> sa \/\/ console.log(sa, ss, sc)<\/span> $<\/span>(<\/span>'.img-box'<\/span>)<\/span>.<\/span>css<\/span>(<\/span>'transform'<\/span>,<\/span> 'rotate('<\/span>+<\/span>allA+<\/span>'deg) scale('<\/span>+<\/span>sc+<\/span>')'<\/span>)<\/span> \/\/ $('.img-box').css('transform', 'scale('+sc+')')<\/span> }<\/span> }<\/span>)<\/span>;<\/span> }<\/span>)<\/span>;<\/span> \/\/ \u5143\u7d20\u79fb\u52a8<\/span> $<\/span>(<\/span>'.img'<\/span>)<\/span>.<\/span>mousedown<\/span>(<\/span>function<\/span> (<\/span>e)<\/span> { \n    <\/span> e.<\/span>preventDefault<\/span>(<\/span>)<\/span> e.<\/span>stopPropagation<\/span>(<\/span>)<\/span> moveMouse =<\/span> true<\/span> if<\/span> (<\/span>init.<\/span>count <<\/span> 1<\/span>)<\/span> { \n    <\/span> init =<\/span> { \n    <\/span> \/\/ X: e.pageX,<\/span> \/\/ Y: e.pageY,<\/span> X<\/span>:<\/span> pointA.<\/span>X<\/span>,<\/span> Y<\/span>:<\/span> pointA.<\/span>Y<\/span>,<\/span> count:<\/span> 1<\/span> }<\/span> }<\/span> var<\/span> dis =<\/span> { \n    <\/span> X<\/span>:<\/span> e.<\/span>pageX -<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>position<\/span>(<\/span>)<\/span>.<\/span>left,<\/span> Y<\/span>:<\/span> e.<\/span>pageY -<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>position<\/span>(<\/span>)<\/span>.<\/span>top }<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mousemove'<\/span>,<\/span> function<\/span> (<\/span>event)<\/span> { \n    <\/span> event.<\/span>preventDefault<\/span>(<\/span>)<\/span> event.<\/span>stopPropagation<\/span>(<\/span>)<\/span> if<\/span> (<\/span>moveMouse)<\/span> { \n    <\/span> var<\/span> end =<\/span> { \n    <\/span>}<\/span> end.<\/span>X<\/span> =<\/span> event.<\/span>pageX -<\/span> dis.<\/span>X<\/span> end.<\/span>Y<\/span> =<\/span> event.<\/span>pageY -<\/span> dis.<\/span>Y<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>css<\/span>(<\/span>{ \n    <\/span> 'left'<\/span>:<\/span> end.<\/span>X<\/span>,<\/span> 'top'<\/span>:<\/span> end.<\/span>Y<\/span> }<\/span>)<\/span> \/\/ console.log($('.box').offset(), $('.box').position(), end, dis)<\/span> pointA =<\/span> { \n    <\/span> \/\/ \u79fb\u52a8\u540e,\u91cd\u65b0\u8ba1\u7b97\u5143\u7d20\u4e2d\u5fc3\u70b9 \u5143\u7d201\/2\u81ea\u8eab\u5bbd\u9ad8 + \u5143\u7d20\u7684\u5b9a\u4f4d<\/span> X<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>width<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>left,<\/span> Y<\/span>:<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>height<\/span>(<\/span>)<\/span> \/<\/span> 2<\/span> +<\/span> $<\/span>(<\/span>'.box'<\/span>)<\/span>.<\/span>offset<\/span>(<\/span>)<\/span>.<\/span>top }<\/span>;<\/span> if<\/span> (<\/span>count ><\/span> 0<\/span>)<\/span> { \n    <\/span> \/\/ \u6bcf\u6b21\u79fb\u52a8\u6309\u4e0b\u7684\u70b9\u4e0d\u4e00\u81f4,\u6709\u8bef\u5dee,\u4f7f\u7528\u4e2d\u5fc3\u70b9\u6765\u8ba1\u7b97<\/span> \/\/ mPointB.X = event.pageX - init.X<\/span> \/\/ mPointB.Y = event.pageY - init.Y<\/span> mPointB.<\/span>X<\/span> =<\/span> pointA.<\/span>X<\/span> -<\/span> init.<\/span>X<\/span> mPointB.<\/span>Y<\/span> =<\/span> pointA.<\/span>Y<\/span> -<\/span> init.<\/span>Y<\/span> mPointB.<\/span>flag =<\/span> true<\/span> }<\/span> \/\/ console.log(pointA, mPointB)<\/span> }<\/span> }<\/span>)<\/span> }<\/span>)<\/span> $<\/span>(<\/span>document)<\/span>.<\/span>on<\/span>(<\/span>'mouseup'<\/span>,<\/span> function<\/span> (<\/span>e)<\/span> { \n    <\/span> typeMouse =<\/span> false<\/span>;<\/span> moveMouse =<\/span> false<\/span> }<\/span>)<\/span>;<\/span> <\/span><\/<\/span>script<\/span>><\/span><\/span> <\/<\/span>html<\/span>><\/span><\/span> <\/code><\/pre>\n

\u8865\u5145\u5185\u5bb9:<\/h3>\n

\u611f\u8c22\u535a\u53cb\u63d0\u51fa\u95ee\u9898,\u5728\u5e73\u79fb\u65f6,\u7531\u4e8e\u6bcf\u6b21\u9f20\u6807\u6309\u4e0b\u7684\u4f4d\u7f6e\u4e0d\u4e00\u6837,\u6211\u662f\u7528\u6700\u540e\u4e00\u6b21\u9f20\u6807\u79fb\u52a8\u7684\u4f4d\u7f6e\u51cf\u53bb\u7b2c\u4e00\u6b21\u9f20\u6807\u6309\u4e0b\u7684\u4f4d\u7f6e, \u5982\u679c\u591a\u6b21\u79fb\u52a8,\u4f38\u7f29\u8ba1\u7b97\u5c31\u4f1a\u6709\u8bef\u5dee<\/p>\n

\u800c\u5143\u7d20\u7684\u4e2d\u5fc3\u70b9\u662f\u4e00\u76f4\u4fdd\u6301\u5728\u5143\u7d20\u4e2d\u5fc3,\u6bcf\u6b21\u79fb\u52a8\u540e\u90fd\u4f1a\u6539\u53d8,\u6240\u4ee5\u6539\u6210\u4f7f\u7528\u6700\u540e\u4e00\u6b21\u79fb\u52a8\u7684\u5143\u7d20\u4e2d\u5fc3\u70b9\u51cf\u53bb\u7b2c\u4e00\u6b21\u79fb\u52a8\u65f6\u7684\u4e2d\u5fc3\u70b9,\u80fd\u6d88\u9664\u8bef\u5dee<\/p>\n

\u4ee3\u7801\u91cc\u7ea2\u8272\u7684\u662f\u4fee\u6539\u540e\u7684<\/p>\n

\u8fd9\u4e2a\u65b9\u6cd5\u4e2dpointB\u7684\u8ba1\u7b97\u6709\u4e9b\u9ebb\u70e6,\u7279\u522b\u662f\u56db\u4e2a\u89d2\u90fd\u4ee5\u65cb\u8f6c\u65f6. \u4e4b\u540e\u53c8\u8bd5\u4e86\u4e00\u79cd\u65b9\u6cd5,\u6bd4\u8f83\u7b80\u5355\u4e00\u4e9b.\u7b2c\u4e8c\u79cd\u5b9e\u73b0\u65b9\u6cd5\u53ef\u4ee5\u770b\u8fd9\u7bc7https:\/\/www.cnblogs.com\/steamed-twisted-roll\/p\/14292478.html<\/p>\n","protected":false},"excerpt":{"rendered":"js\u9f20\u6807\u79fb\u52a8\u5230\u56fe\u7247\u4e0a\u56fe\u7247\u6539\u53d8_javascript\u5c0f\u6e38\u620f\u4ee3\u7801\u535a\u5ba2\u94fe\u63a5\uff1ahttps:\/\/www.cnblogs.com\/steamed-twisted-roll\/p\/13408245.html...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5061"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=5061"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/5061\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=5061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=5061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=5061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}