我正在玩弄 jQuery 和拖放功能。我有一个在 CSSdiv
中设置的。hidden
激活拖动元素时,droppable
应通过设置display
为inline
(这是默认值)来显示元素。
但是,display: inline;
并不推翻display: none;
. 如何做到这一点(通过 jQuery 或 CSS)?
我当前的代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Droppable - Visual feedback</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<style>
#draggable2 { width: 90px; height: 90px; padding: 0.5em; float: left; margin: 10px 10px 10px 0; }
#droppable2 { width: 120px; height: 120px; padding: 0.5em; float: left; margin: 10px; }
#droppable { border-width: 3px; border-style: solid; border-color: #585FCC; height: 20px; display: none; }
.droppable-highlight { display: inline; }
h3 { clear: left; }
</style>
<script>
$(function() {
$( "#draggable2" ).draggable();
$( "#droppable" ).droppable({
accept: "#draggable2",
activeClass: "droppable-highlight",
drop: function( event, ui ) {
$( this )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
}
});
});
</script>
</head>
<body>
<h3>Feedback on activating draggable:</h3>
<div id="draggable2" class="ui-widget-content">
<p>Drag me to my target</p>
</div>
<div id="droppable" >
<p>Drop here</p>
</div>
</body>
</html>
Tinker.io 链接:http ://tinker.io/bf197