使用jQuery调整大小来显示项目的大小
Using jQuery resize to display size of item
想知道是否有人能帮忙。我正在网站上使用可调整大小的jQuery。我想使用伪类将调整大小/可调整大小的对象的大小显示为通知样式的徽章,这应该在每次调整项目大小时更新。CSS不是问题,它获取大小数据并显示它,我对此有意见。有什么办法吗?任何帮助都将不胜感激。我在下面的片段中有错误,所以这里有一个有效的小提琴。
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',
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',
revert:"invalid",
scroll: false
});
});
#icon_menu {
width: 200px;
height: auto;
float: right;
}
#icon_menu li {
width: 45px;
height: 45px;
position: relative;
}
.draggable {
width: 45px;
height: 45px;
border-radius: 50%;
background: rgba(127, 214, 236, 0.5);
}
.droppable {
width: 200px;
height: 100px;
border: 1px solid #000000;
float: left;
}
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%;
}
<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>
您必须同时包含jqueryui库才能使droptable()和draggable()工作。完成后,会有一个方法stop,当调整大小事件完成时会调用它,类似于以下内容:
$element.resizable({
handles: 'e',
ghost: true,
delay: 200,
helper: "overmoused",
minWidth: 20,
start: function(e, ui) {},
resize: function() {},
stop: function(e, ui) {
console.log(ui.originalSize.width, ui.size.width)
}
});
相关文章:
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 我怎样才能重复显示接下来的15个项目
- 隐藏/显示包含单词的ul li项目.但只能入住李的子女
- Javascript中的列表,用于添加和显示所有项目
- 如何在点击时显示ul项目
- 限制ul元素中显示的项目
- 在underscore.js中显示列表中的所有项目(使用Parse.com)
- PHP无法显示带有“”的项目'"在他们身上
- HTML选择,在DOM中选择了正确的选项,但在firefox中显示了错误的项目
- 获取中继器控件ASP.Net中显示的单击项目文本框
- 仅显示具有userid作为子项的项目
- 从项目列表Jquery中仅选择(显示:块)元素
- 首先显示选择最多的项目
- 如果项目不匹配,则显示变量
- 只有一个项目显示在 x 轴 d3 中 - 使用刻度值的序号
- 在 HTML 中将数组的每个项目显示为换行符
- 如何正确使用熨斗可选?像铁页一样使用时,项目显示为null
- Html, javascript:滚动列表框项目-并为每个项目显示提示
- 根据从下拉列表中选择的项目显示ViewBag的属性并发布ID
- 如何向选中的项目显示一个箭头?