\nhttps:\/\/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<\/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
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
\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>