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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745222614a4617318.html
评论列表(0条)