xpanta xpanta - 7 months ago 18
Javascript Question

modify contents of div while dragging with jquery ui draggable

I have a draggable div (jquery ui draggable) which contains mainly text. Can I change the contents of the div while dragging?

(actually, I want to make it a smaller and nicer div)

Answer

Try this out: http://jsfiddle.net/6JtMp/

Here's the code:

<style>
    #draggable { width: 150px; height: 150px; padding: 0.5em; background-color: green; }
    </style>
    <script>
    $(function() {
        $( "#draggable" ).draggable({
            start: function(event, ui) { $(this).css("height",10); },
            stop: function(event, ui) { $(this).css("height",150); }        
        });
    });
    </script>



<div class="demo">

<div id="draggable" class="ui-widget-content">
    <p>Drag me around</p>
</div>

</div><!-- End demo -->