拖曳捲軸 - jQuery UI draggable Options scroll

拖曳捲軸讓你可以決定當拖曳元素超出容器範圍時,是否要讓捲軸無限延伸下去
$("#eleID").draggable({ scroll: false  });

下面有2個範例,分別呈現scroll:true及scroll:false的效果
範例jQuery UI 拖曳捲軸
範例程式碼 Expand
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="http://www.pureexample.com/js/lib/jquery.ui.touch-punch.min.js"></script>


<!-- CSS -->
<style type="text/css">
.drag {	
    width: 100px;
    height: 100px;
    line-height: 100px;
    border: 1px solid black;
    cursor: pointer;
    border-radius: 10px;
    text-align: center;
    background-color: lightpink;
}
</style>


<!-- Javascript -->
<script>
    $(function () {
        $("#drag1").draggable({
            containment: "#box1",
            scroll: true
        });
        
        $("#drag2").draggable({
            containment: "#box2",
            scroll: false
        });
    });
</script>

<!-- HTML -->
捲軸參數設為 <font color="red">true</font>
<div id="box1" style="overflow:scroll;width:500px;height:200px;border:1px solid black;background-color:lightblue">
	<div id="drag1" class="drag">拖曳</div>
</div>
<br>
捲軸參數設為 <font color="red">false</font>
<div id="box2" style="overflow:scroll;width:500px;height:200px;border:1px solid black;background-color:lightblue">
	<div id="drag2" class="drag">拖曳</div>
</div>


comments powered by Disqus