Mootools-使用.implement将变量添加到所有可拖动和可丢弃的元素中
Mootools - add variables to all draggable and droppable elements with .implement
我用mootools的drag.move类制作了一个拖放系统,但我需要所有可拖动和可丢弃的元素都有一些额外的变量,并可能添加一两个函数。我已经研究过如何使用.eimplement来实现这一点,但我不知道如何将其融入我的代码中:
window.addEvent('domready', function(){
$$('#draggables DIV').makeDraggable({
droppables: $$('#droppables DIV'),
onEnter: function(draggable, droppable){
droppable.setStyle('background', 'orange');
droppable.setStyle('opacity', '0.4');
snap_left = droppable.getStyle('left');
snap_top = droppable.getStyle('top');
document.getElementById("slot").innerHTML=droppable.id;
},
onLeave: function(draggable, droppable){
droppable.setStyle('background', null);
},
onDrop: function(draggable, droppable){
if (droppable){
droppable.setStyle('background', '');
draggable.setStyle('left', snap_left );
draggable.setStyle('top', snap_top );
} else {
draggable.setStyle('left', snap_left );
draggable.setStyle('top', snap_top );
}
}
});
});
我想要的东西可以使用.eimplement吗?
我可以将这些东西添加到所有可拖动和可丢弃的元素中吗?
ty提前!
-Thaiscorpion
编辑:
我尝试直接将选项添加到mootools库中的主类中,并尝试从onEnter事件中访问它们,如下所示:
onEnter:函数(可拖动、可丢弃({
if (droppable.occupied){ //here is where im tryin to acces it, the default option is set to occupied: true
droppable.setStyle('background', 'red');
droppable.setStyle('opacity', '0.4');
document.getElementById("slot").innerHTML=droppable.id;
} else {
droppable.setStyle('background', 'orange');
droppable.setStyle('opacity', '0.4');
snap_left = droppable.getStyle('left');
snap_top = droppable.getStyle('top');
document.getElementById("slot").innerHTML=droppable.id;
}
},
但没有得到任何工作。
您可以使用元素存储。
draggable.store("occupied", true);
if (draggable.retrieve("occupied") === true) {
}
每个元件可以存储功能或任何东西
element.store("somekey", function() {
element.toggleClass("foo");
});
element.retrieve("somekey").call(element);
等等。
使用Implement:
Element.implement({
dragfoo: function() {
this.set("drag", { });
return this;
}
});
// allows you:
$("someid").dragfoo();
不过,如果您需要存储,请使用存储,不要将属性存储在实际元素上。mootools存储实际上使用了一个位于闭包后面的对象哈希表。在IE中具有专有的元素属性/属性会大大降低元素访问的速度。
相关文章:
- 如何使元素在可拖动元素内可单击
- 拖动开始时更改可拖动元素的大小
- 无法为HTML5中具有画布和图像的可拖动元素设置“拖动图像”
- 具有可拖动元素的HTML到PDF
- 可缩放容器鼠标上的可拖动元素在创建时从辅助对象上浮动
- 删除所有可拖动元素后如何显示消息
- 将可拖动元素与从父项位置开始的网格对齐
- 拖动元素时,如何获取要替换的元素的位置
- 将id为X的可拖动元素拖放到id为Y的容器
- 在没有jQuery的情况下拖动元素
- 可拖动元素在悬停在另一个'It’s draggable
- 拖动时更改HTML5可拖动元素的“克隆”文本
- Javascript:当元素中有<选择>时,可拖动元素搞砸了
- 是否有可能知道 jquery 可拖动元素将恢复到哪里
- 如何将键控事件与 JQuery-ui 可拖动元素一起使用
- jQuery UI 可拖动元素位于其他可拖动元素下
- 从拖动元素中获取 HTML5 自定义数据属性
- 使用 D3.js 拖动元素时滚动
- 同步两个可拖动元素的位置
- 如何从可拖动元素中删除项目符号