最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - While dragging a div, move another div together with the dragged div - Stack Overflow

programmeradmin3浏览0评论

Two divs are present in different containers. I want to move the div1 in container1 while dragging div2 in container2. (the 'left' property should remain same for div1 and div2 at all times)

I am able to individually drag each of them by applying 'draggable' function. Also I am able to move the div2 while movie div1 by assigning the left property of div1 to the left property of div2 while 'draggable stop' function is called. But this happens only when after the drag event is finished.

Is there a way so that the div2 will move together with div1 all the time while dragging div1?

Please refer to the JSFiddle link to understand what I am trying to do : /

Two divs are present in different containers. I want to move the div1 in container1 while dragging div2 in container2. (the 'left' property should remain same for div1 and div2 at all times)

I am able to individually drag each of them by applying 'draggable' function. Also I am able to move the div2 while movie div1 by assigning the left property of div1 to the left property of div2 while 'draggable stop' function is called. But this happens only when after the drag event is finished.

Is there a way so that the div2 will move together with div1 all the time while dragging div1?

Please refer to the JSFiddle link to understand what I am trying to do : http://jsfiddle/37Wkd/16/

Share Improve this question asked Aug 23, 2012 at 20:33 BlackCursorBlackCursor 1,4922 gold badges17 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6
$('#block1').draggable({
    axis: 'x',
    containment: '#container1',
    drag: function(){
        $('#block2').css('left',$(this).position().left);  
    }

});​

Doesn't this work? Using the drag event: http://jqueryui./demos/draggable/

Try this:

http://jsfiddle/37Wkd/17/

发布评论

评论列表(0)

  1. 暂无评论