javascript - giving an element a temporary fixed width when using jQuery UI draggable? - Stack Overflow

I have some elements that have a relative width. however, when I drag one of these elements using the j

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

Is 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信