Reputation: 42350
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?
Upvotes: 3
Views: 2681
Reputation: 160
Is that it? http://jsfiddle.net/CGQkB/
The trick is to address the of the ui.helper
not just $(this)
since that just points to the original <li>
tag.
Upvotes: 8