javascript - window resize not firing -
i have number of javascript functions. in order stop resize event firing twice, implemented fix, has been working date.
function tabsresize() { cleartimeout(timeout); timeout = settimeout(function () { tabsupdate(); }, 200); } $(window).on("resize", tabsresize);
however, i've created function, sits slighly lower in food chain same thing.
var form = function () { var pub = {}, timeout; function textareaautogrow() { var pad = $(this).outerheight(false) - $(this).innerheight(); this.style.height = "auto"; this.style.height = (this.scrollheight + pad) + "px"; } function textarearesize() { alert("resize"); cleartimeout(timeout); timeout = settimeout(function () { textareaautogrow(); }, 200); } function setupbindings() { $("body").on("input", "textarea", textareaautogrow); $(window).on("resize", textarearesize); } // public functions pub.init = function () { setupbindings(); } return pub; } ();
the problem is not triggering - autogrow function works , there no javascript errors can see - it's resize function.
in order check whether in fact firing, added alert. still no joy.
however, when added second alert tabs resize function both alerts fired. i'm guessing kind of timing issue, don't know how fix it.
anyone advise?
var _timeout = null; function tabsresize() { if(typeof(_timeout)) cleartimeout(_timeout); _timeout = settimeout(function () { alert('=)'); }, 200); } $(window).on("resize", tabsresize);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
var _timeout = null; var form = function () { var pub = {}, timeout; function textareaautogrow() { alert('=)'); var pad = $(this).outerheight(false) - $(this).innerheight(); this.style.height = "auto"; this.style.height = (this.scrollheight + pad) + "px"; } function textarearesize() { alert("resize"); if(typeof(_timeout)) cleartimeout(_timeout); _timeout = settimeout(function () { textareaautogrow(); }, 300); } $("body").on("input", "textarea", textareaautogrow); $(window).on("resize", textarearesize); return pub; } ();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Comments
Post a Comment