Skip to content

Instantly share code, notes, and snippets.

@BKeanu1989
Created April 26, 2018 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BKeanu1989/642c6d2697e556f7339093e26bf51d80 to your computer and use it in GitHub Desktop.
Save BKeanu1989/642c6d2697e556f7339093e26bf51d80 to your computer and use it in GitHub Desktop.
qwertee show all prices nerdy script
function showPrices() {
let prices = Array.from(document.querySelectorAll('.index-tee-list-item span.product-price'));
prices.forEach(function(price) {
price.style.display = "block";
})
}
function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
if (!options) options = {};
var later = function() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
if (!timeout) context = args = null;
};
return function() {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
previous = now;
result = func.apply(context, args);
if (!timeout) context = args = null;
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
};
window.addEventListener('scroll', throttle(showPrices, 3000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment