js如何实现鼠标拖拽旋转功能

js如何实现鼠标拖拽旋转功能,目前我已做成鼠标拖放功能,想加个旋转不知道该怎么做啦,
效果类似美图秀秀app上的图片旋转功能

动漫人物
浏览 1982回答 1
1回答

弑天下

<!DOCTYPE html><html><head><style>&nbsp;div{width:100px;height:100px;background:red;position:relative;}</style><script type="text/javascript" src="js/jquery-1.7.2.min.js"></script><script type="text/javascript">&nbsp; &nbsp; $(function(){&nbsp; &nbsp; &nbsp; &nbsp; var oldY= null;&nbsp; &nbsp; &nbsp; &nbsp; var isdown = false;&nbsp; &nbsp; &nbsp; &nbsp; $("#testcss").mousedown(function(e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isdown = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldY = e.clientY;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; $("html").mousemove(function(e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isdown){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#testcss").css("transform","rotate("+(e.clientY-oldY)+"deg)");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; $("html").mouseup(function(e){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isdown = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; oldY = null;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; });</script></head><body>&nbsp; &nbsp; <div id="testcss"></div></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript