hammer.js

CDN:http://hammerjs.github.io/dist/hammer.min.js
NPM:npm install --save hammer.js

简单拖动示例:
在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>hammer</title>
</head>
<style>
    #app{
        width: 100px;
        height: 100px;
        background: red;
    }
    body{
        margin: 0;
        padding: 0;
    }
</style>
<body>
    
    <div id="app">
        
    </div>

</body>
</html>
<script src="http://hammerjs.github.io/dist/hammer.min.js"></script>
<script>
    const app = document.querySelector('#app');
    const hammertime = new Hammer(app);
    hammertime.on('pan', function(ev) {
        // console.log(ev);
        let w = app.getBoundingClientRect().width
        let h = app.getBoundingClientRect().height

        app.style.marginTop = ev.center.y-(w/2) +'px'
        app.style.marginLeft = ev.center.x-(h/2) +'px'
    });
</script>