The problem I have is that whenever I try to drag and drop with a handle, in the process of drag and drop, the body text will not stay aligned with the text, which is illustrated in the code attached at the end.
The reason why I prefer not to put the handle in the <p> tags, as some of the examples on the web shows, is that i would like to allow user to in place edit the stuff between the p tags, therefore i don’t want to go and do a lot of pre processing (i may add more stuff around the p tags) before displaying the form.
If anyone can shed some light on this matter, it would be greatly appreciated!
Code, using Google CDN, so it should just work:
<head>
<style type="text/css">
#container{
width:500;
}
.handle{
float:left;
}
.
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function(){
$('#container').sortable({
revert:true,
handle:'.handle',
});
});
</script>
</head>
<div id="container">
<div class="c"><span class="handle">HH</span><p>Some text here asdf asdf asdf asdf asdf asd fasd fsa dfsa df asdf sadf sa dfa sdf sadf asd fsa df sadf asdf asdf asd fas df asdf as </p></div>
<div class="c"><span class="handle">HH</span><p>Some text here asdf asdf asdf asdf asdf asd fasd fsa dfsa df asdf sadf sa dfa sdf sadf asd fsa df sadf asdf asdf asd fas df asdf as </p></div>
</div>
The problem is that when the div is dragged to do the sorting, jQuery effectively set’s the
draggable(sodiv.cin your case) to be absolutely positioned (so it can move it around the screen). Not sure about the exact CSS quirks (maybe someone wiser than I can explain more fully), but basically your floating.handleacts a bit strangely in conjunction with thepwhen inside an absolutely positioned container. The margins on thepnow appear to be set from the inside of div rather than merging with them, while thespanis still floating to the top left of the div.One solution is to add the same top margin to the
spanas to thep, but only while its dragging. In other words add the following CSS (I think1emshould be the default margin applied to the top of thep):If you are interested in delving more into the CSS, add the following to your above code & you’ll reproduce the problem without needing the sortables involved: