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?

first code demo

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>

second code demo

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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -