Mootools - 使用 .implement 将变量添加到所有可拖动和可放置的元素
我使用 mootools Drag.move 类制作拖放系统,但我需要所有可拖动和可放置的元素具有一些额外的变量,并且可能添加一两个函数。我研究了如何使用 .implement 来做到这一点,但我不知道如何将其融入到我的代码中:
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 );
}
}
});
});
我想要的是否可以使用 .implement?
我可以将这些东西添加到所有可拖动和可放置的元素中吗?
提前!
-泰国蝎子
编辑:
我尝试直接向 mootools 库中的主类添加选项,并尝试从 onEnter 事件访问它们,如下所示:
onEnter: function(draggable, droppable){
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;
}
},
但没有任何工作。
Im making a drag and drop system with mootools drag.move class, but i need all the draggable and droppable elements to have some extra variables and maybe add in a function or two. Ive researched on how to do this using .implement but Ive got no idea how to fit that into my code:
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 );
}
}
});
});
Is what I want posible using .implement?
Can I add these things to all draggable and droppable elements?
ty in advance!
-Thaiscorpion
edit:
Ive tried adding options directly to the main class in the mootools library and tried accesing them from the onEnter event like this:
onEnter: function(draggable, droppable){
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; } },
but not getting anything to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用元素存储。
....
.... 函数或任何内容都可以按元素存储
,等等。
使用 Implement:
不过,如果您需要存储,请使用存储并且不要在实际元素上存储属性。 mootools 存储实际上使用闭包后面的对象哈希表。在 IE 中拥有专有元素属性可能会大大减慢元素访问速度。
you can use element storage.
....
.... functions or anything can be stored per element
and so forth.
to use Implement:
though if you need storage, use storage and dont store properties on the actual element. mootools storage really uses an object hash table that's behind a closure. having proprietary element attributes/properties in IE can slow things down considerably in element access.