Sorry for the basic level of the question, but js is definitely not my area of โโexpertise. However, this is one of those questions that Google is hard to answer.
Basically I want to do a couple of things when the window is resized. I have some extra code that also stops the resize event twice.
The problem is that I duplicate bits of code, which, as an encoder, I know is wrong. The problem is that I do not know how to do it correctly. Here is my current duplicated code:
Event binding
$(window).on("resize", resizeText);
$(window).on("resize", resizeIndicator);
Functions
function resizeIndicator() {
clearTimeout(id);
id = setTimeout(updateIndicator, 200);
}
function resizeText() {
clearTimeout(id);
id = setTimeout(updateText, 200);
}
Thse are not duplicated but included for completeness:
function updateIndicator() {
$tab = $(".tabs li.focus");
if ($tab.length) {
toggleIndicator($tab, true);
}
}
function updateText() {
$tabs = $(".tabs li:not(.indicator) a");
$tabs.each(function () {
$(this).toggleClass("two-line", this.scrollWidth > $(this).outerWidth());
});
}
source
share