I have a function that i have to run only once if specific width is reached.
Function is used to transpose table (columns with rows) only on mobile
What I need:
1. ON LOAD a. if width <992 run transposeTable (mobiles) b. if width> 992 do nothing 2. ON RESIZE a. if width <992 run transposeTable ONLY ONCE BUT if loaded page has a smaller width than 992px do nothing (see 1) b. if width> 992 run transponseTable ONLY ONCE BUT if loaded page has a width greater than 992px to nothing (see 1) here's solution (with some modifications) thanks to @Olaf Nankman
var transposed = "desktop"; $(document).ready(function(){ if($(window).width() < 992){ transposed = "mobile" transposeTable(); }else{ transposed = "desktop" } }) $(window).resize(function(){ if($(window).width() < 992 && transposed != "mobile"){ transposed = "mobile" transposeTable(); } if($(window).width() > 992 && transposed != "desktop"){ transposed = "desktop" transposeTable(); } })
transposeTable()onifandelse? and what problem you are facing now?var isTransposed = false;function transposeTable() { if (isTransposed) return; isTransposed = true; ...