<html>
<head>
<style>
.draggable {background-color:green; width: 90px; height: 80px; padding: 5px; float: left; margin: 0 10px 10px 0; font-size: .9em; }
.droppable { width: 300px; height: 300px; background-color:red}
</style>
</head>
<body>
<div>
<p>I revert when I'm not dropped</p>
</div>
<div>
<p>Drop me here</p>
</div>
<script type="text/javascript" src="https://www.jb51.net/js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/js/jquery-ui-1.8.16.custom.min.js"></script>
<script>
$(function() {
$( "#draggable2" ).draggable({ revert: "invalid",cursor: "move", cursorAt: { top: 56, left: 56 } });
$( "#droppable" ).droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
});
</script>
</body>
</html>
小结
JQuery UI提供了强大的拖拽功能和良好的用户体验,同时又非常容易使用。本文介绍了常用的各种用法。更多的参数还可以参考官方网站的Draggable 和 Droppable 。
您可能感兴趣的文章: