English | 正體中文 | 简体中文

Jquery ui draggable events



范例程式码 Expand
<!-- Javascript -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
  	var count1 = 0, count2 = 0, count3 = 0;
    $(function () {
        $("#drag").draggable({
            containment: "#box",
            start: function() {
              count1++;
              $("#info1").html("Start " + count1);	
            },
            drag: function() {
              count2++;	
              $("#info2").html("Drag " + count2);
            },
            stop: function() {
              count3++;	
              $("#info3").html("Stop " + count3);
            }            
        });
    });
</script>

<!-- HTML -->
<style>
    .drag { 
        width: 100px; 
        height: 100px;     
        border:1px solid black; 
        cursor:pointer;
        border-radius:10px;
        padding:5px;
        margin-left:5px;
        text-algin:center;
        float:left;
    }
  
    .info{
      width:100px;
      height:20px;
      border:1px solid black;
      text-align:center;
      margin-bottom:2px;
  	}
</style>
<div id="box" style="width:600px;height:200px;border:0px solid black;margin-bottom:5px">
    <div id="drag" class="drag">
        <p>Drag me</p>
    </div>
</div>
<div id="info1" class="info">Start</div>
<div id="info2" class="info">Drag</div>
<div id="info3" class="info">Stop</div>

    
在线测试程序
© 2012 PureExample.com contact