我想要一個可拖動的 div。我有一個解決方案,它可以作業,但我想只用一個小方塊來拖動該div
。 。span class="hljs-selector-class">.bat {
position: absolute;
width: 600px;
height: 125px;
background-color: #262626;
}
.batdrag {
cursor: move;
width: 45px;
height: 30px;
float: left;
margin: 0px 10px;
background-color: #0000FF;
border-radius: 4px;
}
<div class=bat> /span>
<div class="batdrag"/span>> </div>>
</div>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
如果有這樣的Jquery代碼:
$(function(/span>) {
$(".batdrag"/span>).draggable()。
});
但是它只移動了藍色的 div,而我想把灰色的 div 和藍色的 div 一起移動。這可能嗎?
uj5u.com熱心網友回復:
你可以使用內置的handle設定來實作這一點。選擇.bat元素并在其上定義draggable(),然后設定.batdrag作為手柄來移動外部元素:
$(".bat").draggable({
handle: '.batdrag'。
});
.bat {
position: absolute;
width: 600px;
height: 125px;
background-color: #262626;
}
.batdrag {
cursor: move;
width: 45px;
height: 30px;
float: left;
margin: 0px 10px;
background-color: #0000FF;
border-radius: 4px;
}
<script src="https://cdnjs. cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>/span>
<script src="https://code. jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel=" stylesheet" href="https://code. jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />。
<div class="bat"/span>>
<div class="batdrag"/span>> </div>>
</div>/span>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/319954.html
標籤:
上一篇:實作雙端滑動視窗的用戶界面
