- script.aculo.us 教程
- script.aculo.us - 主頁
- script.aculo.us - 概覽
- script.aculo.us - 模組
- script.aculo.us - 視覺效果
- script.aculo.us - 拖放
- script.aculo.us - 分類元素
- script.aculo.us - 建立滑塊
- script.aculo.us - 自動完成
- script.aculo.us - 就地編輯
- script.aculo.us 資源
- script.aculo.us - 快速指南
- script.aculo.us - 資源
- script.aculo.us - 討論
使用貪婪選項進行拖放
說明
如果將此選項設定為 true(預設值),它將停止處理懸停在可拖放項上方的其他專案,將不會搜尋可拖放項下方。
語法
Droppables.add('element', {greedy: false or true});
示例
逐個將 greedy 設定為 true 和 false,嘗試此示例。你會發現如果你將 greedy 設定為 false,則你無法將專案拖到目標區域。
<html>
<head>
<title>Drag and Drop Example</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script type = "text/javascript" src = "/javascript/scriptaculous.js"></script>
<script type = "text/javascript">
window.onload = function() {
// Make all the images draggables from draggables division.
$A($('draggables').getElementsByTagName('img')).each(function(item) {
new Draggable(item, {revert: true, ghosting: true});
});
Droppables.add('droparea',
{
hoverclass: 'hoverActive',
greedy: false,
onDrop: moveItem
}
);
// Set drop area by default non cleared.
$('droparea').cleared = false;
}
// The target drop area contains a snippet of instructional
// text that we want to remove when the first item
// is dropped into it.
function moveItem( draggable,droparea){
if (!droparea.cleared) {
droparea.innerHTML = '';
droparea.cleared = true;
}
draggable.parentNode.removeChild(draggable);
droparea.appendChild(draggable);
}
</script>
<style type = "text/css">
#draggables {
width: 172px;
border: 3px ridge blue;
float: left;
padding: 9px;
}
#droparea {
float: left;
margin-left: 16px;
width: 172px;
border: 3px ridge maroon;
text-align: center;
font-size: 24px;
padding: 9px;
float: left;
}
.hoverActive {
background-color: #ffffcc;
}
#draggables img, #droparea img {
margin: 4px;
border:1px solid red;
}
</style>
</head>
<body>
<div id = "draggables">
<img src = "/images/html.gif"/>
<img src = "/images/css.gif"/>
<img src = "/images/xhtml.gif"/>
<img src = "/images/wml_logo.gif"/>
<img src = "/images/javascript.gif"/>
</div>
<div id = "droparea">
Drag and Drop Your Images in this area
</div>
</body>
</html>
將產生以下結果 −
scriptaculous_drag_drop.htm
廣告