Answer the question
In order to leave comments, you need to log in
How to make .scrollTop() as a percentage?
Hello.
Is it possible to bind .scrollTop()
to percentages (preferably vh) rather than pixels?
For example code:
$(document).ready(function() {
var $header = $("#header");
$(window).scroll(function() {
if ($(this).scrollTop() > 700 && $header.hasClass("transparent")) {
$header.removeClass("transparent").addClass("opacity");
} else if ($(this).scrollTop() <= 700 && $header.hasClass("opacity")) {
$header.removeClass("opacity").addClass("transparent");
}
}); //scroll
});
With it, classes are added or removed depending on the scroll. In this case, you need to scroll 700px to change it. I need the metering to take place in percent (or vh). That is, for example, if I scrolled 80% of the window (or viewport), then the class changes.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question