admin管理员组文章数量:1418679
I need to replace the Bind event from JQuery with some event from JavaScript.
I am developing a Bookmarklet and i received order to replace jQuery with JavaScript
I have the following code
$(document).unbind("mousemove", X.highlighter);
$(document).bind("mousemove", X.highlighter);
and also
var current, overlay = $("#overlayhighlight"), o = $('#y');
this last 3 I can replace with document.getElementsByID
the bind and unbind ... no clue
I need to replace the Bind event from JQuery with some event from JavaScript.
I am developing a Bookmarklet and i received order to replace jQuery with JavaScript
I have the following code
$(document).unbind("mousemove", X.highlighter);
$(document).bind("mousemove", X.highlighter);
and also
var current, overlay = $("#overlayhighlight"), o = $('#y');
this last 3 I can replace with document.getElementsByID
the bind and unbind ... no clue
Share Improve this question asked Jun 15, 2012 at 9:50 Ionut Flavius PogacianIonut Flavius Pogacian 4,81115 gold badges62 silver badges101 bronze badges 4- JQuery has great cross-browser support, tell your client that JQuery is more reliable ;-) – musefan Commented Jun 15, 2012 at 9:51
- we know, but this is a plex bookmarklet and we should use only js; if a website does not have jquery, the bookmarklet will crack instalntly – Ionut Flavius Pogacian Commented Jun 15, 2012 at 9:54
- Why don't you then load jQuery in the bookmarklet if it doesn't exist then? You cannot just replace these with javascript, jQuery events include dozens of fixes and features you might be using. Every little thing you have taken for granted must be now coded by you. – Esailija Commented Jun 15, 2012 at 9:58
- no jquery code is allowed; it could break the website or bookmarklet; i did not know this when i started, but now, jquery must not be used; it's plicated :d – Ionut Flavius Pogacian Commented Jun 15, 2012 at 10:02
6 Answers
Reset to default 3document.onmousemove(function(){
//do something here
});
var current, overlay = doucment.getElementById("overlayhighlight"), o = docuemnt.getElementById('y');
You can replace jquery code by javascript code like above
Have a look at element.addEventListener()
(MDN docu) and element.removeEventListener
(MDN docu).
document.addEventListener( 'mousemove', X.highlighter );
document.removeEventListener( 'mousemove', X.highlighter );
Use the below sample to attach simple events
if (document.addEventListener) {
document.addEventListener('mousemove', modifyText, false);
} else if (document.attachEvent) {
document.attachEvent('onmousemove', modifyText);
}
Add this to the top of your script and work with jQuery as usual, if a website does not have jquery, doesn't matter.
var js = document.createElement("https://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js");
js.type = "text/javascript";
js.src = jsFilePath;
document.body.appendChild(js);
document.onmousemove=X.highlighter;//bind
document.onmousemove=null;//unbind
Check our this link for lots of mouse event information, more specifcally this one:
Mousemove
The mousemove event works fine, but you should be aware that it may take quite some system time to process all mousemove events. If the user moves the mouse one pixel, the mousemove event fires. Even when nothing actually happens, long and plicated functions take time and this may affect the usability of the site: everything goes very slowly, especially on old puters.
Therefore it’s best to register an onmousemove event handler only when you need it and to remove it as soon as it’s not needed any more:
element.onmousemove = doSomething;
// later
element.onmousemove = null;
本文标签: Replace Bind event from jQuery with something from JavascriptStack Overflow
版权声明:本文标题:Replace Bind event from jQuery with something from Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745268576a2650752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论