How To Call Function Only Once In Resize Function?
Any idea how I can make a function be called only once using .resize, and then have it permanently cancelled or disabled? $(window).resize(function () { if ($(window).width()
Solution 1:
jQuery has the .one
method for that:
$(window).one("resize", function () { /* */ });
Solution 2:
Use one
function http://api.jquery.com/one/
$(window).one('resize',function () {
if ($(window).width() < 800){
size = true;
mob();
}
});
$(window).trigger('resize');
Or on/off
functions http://api.jquery.com/on/
$(window).on('resize',function () {
if ($(window).width() < 800){
size = true;
mob();
}
});
$(window).trigger('resize').off('resize');
Post a Comment for "How To Call Function Only Once In Resize Function?"