Create a draggable div in native javascript [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: Moveable/draggable 5 answers I want to create a movable/draggable div in native javascript without using jquery and libraries. Is there a tutorial or anythign? 回答1: OK, here's my personal code that I use for lightweight deployments (projects where using a library is either not allowed or overkill for some reason). First thing first, I always use this convenience function so that I can pass either an id or the actual dom element: function get (el) { if (typeof el == 'string') return document