JS——jquery UI

    1. draggable()javascript

滑動條demo:css

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        .con{
            width:300px;
            height:300px;
            border:1px solid #000;
            margin:50px auto 0;
        }

        .box{
            width:50px;
            height:50px;
            background-color:hotpink;
            cursor:pointer;
        }
    </style>
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //使得box能夠鼠標拖動
            $('.box').draggable({
                //約束元素在父級內拖動
                containment:'parent',
                //約束元素只能橫向拖動
                axis:'x',
                //元素拖動時透明度變爲0.6
                opacity:0.6,
                //ui裏面有什麼能夠用console.log(ui)查看
                drag:function (ev,ui) {
                    var nowleft = ui.position.left;
                }
            });
        })
    </script>
</head>
<body>
    <div class="con">
        <div class="box"></div>
    </div>
</body>
</html>
相關文章
相關標籤/搜索