admin管理员组文章数量:1022688
I've got a JavaScript function with an eventListener for `dragover.
It looks like this:
document.getElementById("someID").addEventListener("dragover",
function(){
//Do logic
},
false);
The thing is - someID
will be a dynamic element - it gets removed and added on the page. After it's removed and added back in, the eventListener will no longer pickup the dragover
event. The only way I know of how to deal with this situation is to use jQuery's .on()
My problem: I can't find the dragover
event under jQuery API... Does it even exist? If not how can I use it in jQuery?
I've got a JavaScript function with an eventListener for `dragover.
It looks like this:
document.getElementById("someID").addEventListener("dragover",
function(){
//Do logic
},
false);
The thing is - someID
will be a dynamic element - it gets removed and added on the page. After it's removed and added back in, the eventListener will no longer pickup the dragover
event. The only way I know of how to deal with this situation is to use jQuery's .on()
My problem: I can't find the dragover
event under jQuery API... Does it even exist? If not how can I use it in jQuery?
1 Answer
Reset to default 3You can define a customer drag event as,
(function(jQuery) {
//Defining drag event.
jQuery.fn.drag = function() {
eventType = arguments[0] || 'dragstart';
onEvent = typeof arguments[1] == 'function' ? arguments[1] : function() {
};
eventOption = arguments[2] || false;
$(document).on('mouseover', $(this).selector, function() {
if ($(this).hasClass(eventType)) {
return;
}
if (! typeof eventType == 'string') {
return;
}
console.log('Binding Drag Event');
$(this).each(function() {
$(this)[0].addEventListener(eventType, onEvent, eventOption);
$(this).addClass(eventType);
})
});
}
})(jQuery);
And then you have to add this as a plugin and apply it for required selector as follows.
$('#someID').drag('dragover', function(){
//Do logic
alert('DRAGGING!!!!!!');
},
false);
Working fiddle http://jsfiddle/sadepu/aDYfP/
I've got a JavaScript function with an eventListener for `dragover.
It looks like this:
document.getElementById("someID").addEventListener("dragover",
function(){
//Do logic
},
false);
The thing is - someID
will be a dynamic element - it gets removed and added on the page. After it's removed and added back in, the eventListener will no longer pickup the dragover
event. The only way I know of how to deal with this situation is to use jQuery's .on()
My problem: I can't find the dragover
event under jQuery API... Does it even exist? If not how can I use it in jQuery?
I've got a JavaScript function with an eventListener for `dragover.
It looks like this:
document.getElementById("someID").addEventListener("dragover",
function(){
//Do logic
},
false);
The thing is - someID
will be a dynamic element - it gets removed and added on the page. After it's removed and added back in, the eventListener will no longer pickup the dragover
event. The only way I know of how to deal with this situation is to use jQuery's .on()
My problem: I can't find the dragover
event under jQuery API... Does it even exist? If not how can I use it in jQuery?
1 Answer
Reset to default 3You can define a customer drag event as,
(function(jQuery) {
//Defining drag event.
jQuery.fn.drag = function() {
eventType = arguments[0] || 'dragstart';
onEvent = typeof arguments[1] == 'function' ? arguments[1] : function() {
};
eventOption = arguments[2] || false;
$(document).on('mouseover', $(this).selector, function() {
if ($(this).hasClass(eventType)) {
return;
}
if (! typeof eventType == 'string') {
return;
}
console.log('Binding Drag Event');
$(this).each(function() {
$(this)[0].addEventListener(eventType, onEvent, eventOption);
$(this).addClass(eventType);
})
});
}
})(jQuery);
And then you have to add this as a plugin and apply it for required selector as follows.
$('#someID').drag('dragover', function(){
//Do logic
alert('DRAGGING!!!!!!');
},
false);
Working fiddle http://jsfiddle/sadepu/aDYfP/
本文标签: javascriptjQueryusing JS events like quotdragoverquotStack Overflow
版权声明:本文标题:javascript - jQuery - using JS events like "dragover" - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745532399a2154808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论