Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function debounce(func, wait, immediate) {
- var timeout;
- return function() {
- var context = this, args = arguments;
- var later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- };
- function breakAfterFirstWord(){
- const h1 = document.querySelector("h1").innerHTML;
- const splittedh1 = h1.split(" ");
- if(window.innerWidth < 768 && splittedh1.length === 2){
- splittedh1.splice(1, 0, '</br>');
- document.querySelector("h1").innerHTML = splittedh1.join(' ');
- } else if(window.innerWidth > 767 && splittedh1.length === 3){
- splittedh1.splice(1, 1);
- document.querySelector("h1").innerHTML = splittedh1.join(' ');
- }
- }
- var myEfficientFn = debounce(function() {
- breakAfterFirstWord();
- }, 250);
- window.addEventListener('resize', myEfficientFn);
- breakAfterFirstWord()
Add Comment
Please, Sign In to add comment