I want to do the equivalent of this:
$(window).bind('resize', function () {
myResizeFunction();
}).trigger('resize');
without jquery.
The reason being is. This is the only part of code in my javascript library that uses jquery.
And i see no point in includin开发者_C百科g jquery if im only using this one command.
NOTE: Just to clarify, i want myResizeFunction to run everytime the broswer is resized. A cross-browser solution is prefered!
Thanks:)
Simply use this
<script>
var resizeMe = function() {
myResizeFunction();
}
resizeMe();
</script>
To hook with resize event of window
window.onresize = resizeMe
As far as I know, jQuery is simply using window.onresize
.
window.onresize = function() {
//stuff
};
For your case:
window.onresize = myResizeFunction;
myResizeFunction();
// binding event
if(window.addEventListener)window.addEventListener("resize",myResizeFunction,false);
else if(window.attachEvent)window.attachEvent("onresize",myResizeFunction);
// trigger event handler
myResizeFunction();
It's not full equivalent of jQuery .bind
and .trigger
, but it's valid main usage of resize
event
精彩评论