我試圖將我的可拖動區域限制為背景(.bg),但是一旦我這樣做,視窗只能垂直拖動,盡管背景的寬度為 100%。
我嘗試將約束設定為“body”和“parent”,所有這些都導致了相同的問題。
我怎樣才能使我的視窗可以向各個方向拖動?
$( function() {
$( ".draggable" ).draggable({
handle: ".window-titlebar",
scroll: false,
containment: ".bg"
});
} );
/* - - - GENERAL - - - */
body,html {
font-family: Roboto;
font-size: 18px;
height: 100%;
width: 100%;
margin: 0;
}
.bg {
background-image: url("http://abload.de/img/background4mqdx.jpg");
height: 100%;
width: 100%;
background-size: cover;
background-repeat: no-repeat;
}
/* - - - WINDOWS - - - */
.window {
display: flex;
flex-direction: column;
min-width: 30%;
width: fit-content;
padding: 4px 5px 5px 4px;
height: 70%;
box-shadow: -1px -1px 0px 0px #000 inset, 1px 1px 0px 0px #FFF inset, -2px -2px 0px 0px #868A8E inset;
background-color: #C2C5CA;
margin: 0 auto;
}
.window-titlebar {
display: block;
background: linear-gradient(to right, #000080, #0992ec);
position: relative;
width: 100%;
height: 25px;
color: #FFF;
}
.window-titlebar > .tab-icon {
margin-right: 5px;
}
.window-option-bar {
display: block;
position: relative;
width: 100%;
height: 18px;
padding: 5px 0px 8px 0px;
}
.window-option {
-webkit-user-select: none;
padding: 2px 5px 2px 5px;
cursor: pointer;
}
.window-option:hover {
box-shadow: 2px 2px 0px 0px #000 inset, -1px -1px 0px 0px #FFF inset;
}
.window-content {
margin-left: auto;
margin-right: auto;
display: block;
width: calc(98.5% - 7px);
height: 100%;
border: 2px solid #C2C5CA;
box-shadow: -1px -1px 0px 0px #000, 1px 1px 0px 0px #FFF;
background-color: #FFF;
overflow: scroll;
padding: 5px;
}
<!-- JavaScript -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<div class="bg">
<!-- Windows -->
<div class="window menu-context draggable" id="credits-window" >
<div class="window-titlebar">
<div class="tab-icon"></div> credits - Notepad
</div>
<div class="window-option-bar">
</div>
<div class="window-content">
hewwo
</div>
</div>
</div>
</body>
uj5u.com熱心網友回復:
我認為這個問題已經解決了,但以防萬一。只需將帶有值
的 css 屬性添加到類中,它應該可以作業。positionabsoulte.window
$( function() {
$( ".draggable" ).draggable({
handle: ".window-titlebar",
scroll: false,
containment: ".bg"
});
} );
/* - - - GENERAL - - - */
body,html {
font-family: Roboto;
font-size: 18px;
height: 100%;
width: 100%;
margin: 0;
}
.bg {
background-image: url("http://abload.de/img/background4mqdx.jpg");
height: 100%;
width: 100%;
background-size: cover;
background-repeat: no-repeat;
}
/* - - - WINDOWS - - - */
.window {
position:absolute;
display: flex;
flex-direction: column;
min-width: 30%;
width: fit-content;
padding: 4px 5px 5px 4px;
height: 70%;
box-shadow: -1px -1px 0px 0px #000 inset, 1px 1px 0px 0px #FFF inset, -2px -2px 0px 0px #868A8E inset;
background-color: #C2C5CA;
margin: 0 auto;
}
.window-titlebar {
display: block;
background: linear-gradient(to right, #000080, #0992ec);
position: relative;
width: 100%;
height: 25px;
color: #FFF;
}
.window-titlebar > .tab-icon {
margin-right: 5px;
}
.window-option-bar {
display: block;
position: relative;
width: 100%;
height: 18px;
padding: 5px 0px 8px 0px;
}
.window-option {
-webkit-user-select: none;
padding: 2px 5px 2px 5px;
cursor: pointer;
}
.window-option:hover {
box-shadow: 2px 2px 0px 0px #000 inset, -1px -1px 0px 0px #FFF inset;
}
.window-content {
margin-left: auto;
margin-right: auto;
display: block;
width: calc(98.5% - 7px);
height: 100%;
border: 2px solid #C2C5CA;
box-shadow: -1px -1px 0px 0px #000, 1px 1px 0px 0px #FFF;
background-color: #FFF;
overflow: scroll;
padding: 5px;
}
<!-- JavaScript -->
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<body>
<div class="bg">
<!-- Windows -->
<div class="window menu-context draggable" id="credits-window" >
<div class="window-titlebar">
<div class="tab-icon"></div> credits - Notepad
</div>
<div class="window-option-bar">
</div>
<div class="window-content">
hewwo
</div>
</div>
</div>
</body>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/430906.html
標籤:jQuery jQuery-ui jquery-ui-可拖动
上一篇:掉出盒子的物品
下一篇:每行只勾選一個復選框
