简体   繁体   中英

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)

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 -->

What about drag ?

drag( event, ui )

Triggered while the mouse is moved during the dragging, immediately before the current move happens.

Just specify the drag callback:

$( "#draggable" ).draggable({
  drag: function( event, ui ) {
      // do something while dragging
  }
});

There are three different events that you can hook into which will probably enable you to do what you are looking for. I would check out defining functions for the start, drag, and or stop events. Here is the api doc: http://jqueryui.com/demos/draggable/#event-drag

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM