English | 正體中文 | 简体中文

Jquery ui draggable containment



范例程式码 Expand
<!-- Javascript -->
<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>
    $(function () {
        $("div[id='dragx']").draggable({
            containment: "#box",
            scroll: false
        });
    });
</script>

<!-- HTML -->
<style>
    .drag { 
        width: 100px; 
        height: 100px;     
        border:1px solid black; 
        cursor:pointer;
        border-radius:10px;
        padding:5px;
        margin-left:5px;
        text-algin:center;
        float:left;
    }
</style>
<div id="box" style="width:300px;height:200px;border:1px solid black;">
	<div id="dragx" class="drag"><p>Drag me</p></div>
</div>

    
在线测试程序
© 2012 PureExample.com contact