JQueryUI-拖動(Draggable)-在DOM 元素中約束運動

來源:互聯網
上載者:User

標籤:jqueryui-拖動(draggable)-在dom 元素中約束運動

定義和用法
通過定義 draggable 地區的邊界來約束每個 draggable 的運動,使用 containment 選項來指定一個父級的 DOM 元素或者一個 jQuery 選取器


樣本
<!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>draggable</title><link rel="stylesheet" href="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.css"><style>.draggable{width: 90px;height: 90px;padding: 0.5em;float: left;margin: 0 10px 10px 0;cursor: move}h3{clear:left;}#containment-wrapper{width:95%;height: 450px;border:2px solid #ccc;padding:10px;}</style></head><body><h3>在DOM 元素中約束運動:</h3><div id="containment-wrapper"><div id="draggable1" class="draggable ui-widget-content"><p>我被約束在盒子裡</p></div><div class="draggable ui-widget-content"><p id="draggable2" class="ui-widget-header">我被約束在父元素內</p></div></div><script src="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/external/jquery/jquery.js" type="text/javascript" ></script><script src="js/jquery-ui-1.12.1.custom/jquery-ui-1.12.1.custom/jquery-ui.min.js"></script><script>$("#draggable1").draggable({containment:"#containment-wrapper",scroll:false});$("#draggable2").draggable({containment:"parent"});</script></body></html>


輸出

650) this.width=650;" src="https://s5.51cto.com/wyfs02/M01/8D/A6/wKioL1ilOvWTCghMAABERjHsyIc656.png-wh_500x0-wm_3-wmp_4-s_1144824128.png" title="QQ20170216133825.png" alt="wKioL1ilOvWTCghMAABERjHsyIc656.png-wh_50" />

本文出自 “素顏” 部落格,請務必保留此出處http://suyanzhu.blog.51cto.com/8050189/1898428

JQueryUI-拖動(Draggable)-在DOM 元素中約束運動

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.