admin管理员组文章数量:1415664
I have some elements that have a relative width. however, when I drag one of these elements using the jquery UI's draggable()
method, it shifts based on where I'd like to drag it. I tried the following code, attempting to use the start and stop callbacks:
HTML:
<ul id='item-list'>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
CSS
#item-list {
width: 40%;
}
#item-list li {
width: 100%;
}
JavaScript
$("#item-list li").draggable({
revert : true,
helper : 'clone',
start : function() {
$(this).css('width',$(this).width());
},
stop : function() {
$(this).css('width','100%');
}
});
However, this only seems to work the second time I drag objects. is there some way to get this to work properly?
I have some elements that have a relative width. however, when I drag one of these elements using the jquery UI's draggable()
method, it shifts based on where I'd like to drag it. I tried the following code, attempting to use the start and stop callbacks:
HTML:
<ul id='item-list'>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
CSS
#item-list {
width: 40%;
}
#item-list li {
width: 100%;
}
JavaScript
$("#item-list li").draggable({
revert : true,
helper : 'clone',
start : function() {
$(this).css('width',$(this).width());
},
stop : function() {
$(this).css('width','100%');
}
});
However, this only seems to work the second time I drag objects. is there some way to get this to work properly?
Share Improve this question asked Jul 23, 2012 at 15:40 GStoGSto 42.4k37 gold badges136 silver badges188 bronze badges1 Answer
Reset to default 8Is that it? http://jsfiddle/CGQkB/
The trick is to address the of the ui.helper
not just $(this)
since that just points to the original <li>
tag.
本文标签: javascriptgiving an element a temporary fixed width when using jQuery UI draggableStack Overflow
版权声明:本文标题:javascript - giving an element a temporary fixed width when using jQuery UI draggable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745222613a2648464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论