draggable - jquery ui

2022. 1. 24. 16:21카테고리 없음

*필요한 파일 3가지

  - jquery-ui.min.css

  - jquery-2.2.4.min.js

  - jquery-ui.min.js

 

https://stackoverflow.com/questions/47885271/jquery-draggable-is-not-a-function


position absolute 필요 없고 부모 태그 안에서 움직임

 

<!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>Document</title>
    <link rel="stylesheet" href="./jquery-ui.min.css">
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"
        integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <script src="./jquery-ui.min.js" defer></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        .box {
            width: 100%;
            height: 100vh;
            background-color: antiquewhite;
        }

        .drag {
            width: 200px;
            height: 200px;
            background-color: #fff;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="drag">

        </div>
    </div>

    <script>
        jQuery(document).ready(function () {
            $('.drag').draggable({
                scroll: false,
                containment: 'parent', //부모 요소 안에서만 이동 범위 제한 handle : '.header'
            });
        });
    </script>
</body>

</html>

자유 자재로 움직인다. 신기해