- 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 - 讨论
拖放和接受选项
描述
这是一个字符串或一个描述 CSS 类的字符串数组。此可拖放元素仅接受具有一个或多个这些 CSS 类的可拖动元素。
语法
Droppables.add('element', {accept: 'cssClass'});
这里 cssClass 是一个 CSS 类,只有具有该类的元素才接受拖放区域。你可以指定一个 CSS 类数组。
示例
在此示例中,你只能拖放具有“niceOne”CSS 类的图像。
<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', accept: 'niceOne', 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; } .niceOne { border:10px dotted red; } #draggables img, #droparea img { margin: 4px; border:1px solid red; } </style> </head> <body> <div id = "draggables"> <img class = "niceOne" src = "/images/html.gif"/> <img src = "/images/css.gif" /> <img class="niceOne" src = "/images/xhtml.gif"/> <img src = "/images/wml_logo.gif"/> <img class="niceOne" src = "/images/javascript.gif"/> </div> <div id = "droparea"> Drag and Drop Your Images in this area </div> </body> </html>
将产生以下结果−
scriptaculous_drag_drop.htm
广告