想知道是否有人可以提供幫助。我在網站上使用jQuery可調整大小。我想使用僞類將調整大小/可調整大小的對象顯示爲通知樣式徽章,每次調整項目大小時都應該更新。 CSS不是問題,它獲取大小數據並顯示我遇到的問題。任何想法如何把這個關掉?任何幫助都感激不盡。我在下面的代碼片段中有錯誤,所以這裏有一個小工具可以使用。使用jQuery調整大小來顯示項目的大小
https://jsfiddle.net/adrian_babb/xwaokufj/
<ul id="icon_menu">
<li class="draggable"></li>
</ul>
draggable.ui-resizable:after {
content: "";
position: absolute;
top: -5px;
right: -5px;
font-size: .7em;
background-color: #5f6a72;
color: #ffffff;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
border-radius: 50%;
}
<script>
$(document).ready(function($) {
$(".droppable").droppable({
accept: '.draggable',
drop: function(event, ui) {
var $clone = ui.helper.clone();
if (!$clone.is('.inside-droppable')) {
$(this).append($clone.addClass('inside-droppable').draggable({
containment: '.droppable',
scroll: false,
tolerance: 'pointer',
position: 'relative',
}));
$clone.resizable({
aspectRatio: 'true',
ghost: 'true',
handles: 'ne, nw, se, sw',
maxHeight: 200,
maxWidth: 200,
minHeight: 30,
minWidth: 30
});
}
}
});
$(".draggable").draggable({
helper: 'clone',
$(document).ready(function($) {
$(".droppable").droppable({
accept: '.draggable',
drop: function(event, ui) {
var $clone = ui.helper.clone();
if (!$clone.is('.inside-droppable')) {
$(this).append($clone.addClass('inside-droppable').draggable({
containment: '.droppable',
\t \t \t \t \t scroll: false,
\t \t \t \t \t tolerance: 'pointer',
\t \t \t \t \t position: 'relative',
}));
$clone.resizable({
\t \t \t \t \t aspectRatio: 'true',
\t \t \t \t \t ghost: 'true',
\t \t \t \t \t handles: 'ne, nw, se, sw',
\t \t \t \t \t maxHeight: 200,
\t \t \t \t \t maxWidth: 200,
\t \t \t \t \t minHeight: 30,
\t \t \t \t \t minWidth: 30
});
}
}
});
$(".draggable").draggable({
helper: 'clone',
\t \t revert:"invalid",
\t \t scroll: false
});
});
#icon_menu {
\t width: 200px;
\t height: auto;
\t float: right;
}
#icon_menu li {
\t width: 45px;
\t height: 45px;
\t position: relative;
}
.draggable {
\t width: 45px;
\t height: 45px;
\t border-radius: 50%;
\t background: rgba(127, 214, 236, 0.5);
}
.droppable {
\t width: 200px;
\t height: 100px;
border: 1px solid #000000;
float: left;
}
draggable.ui-resizable:after {
\t content: "";
\t position: absolute;
\t top: -5px;
\t right: -5px;
\t font-size: .7em;
\t background-color: #5f6a72;
\t color: #ffffff;
\t width: 20px;
\t height: 20px;
\t text-align: center;
\t line-height: 20px;
\t border-radius: 50%;
}
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<ul id="icon_menu">
<li class="draggable"></li>
</ul>
請嘗試添加小提琴或內容片段在你的情況... –
片段沒有按」運行。 – ksav
抱歉我的代碼段有腳本錯誤。不知道爲什麼所以我添加了一個似乎工作正常的小提琴 – user3433046