Hi, in this code, already is working with jquery, but how can i convert to JavaScript the following:
$(window).on("scroll", function () {
if (checkVisible($("#target"))) {
$("#something").html(
`HTML CONTENT`
);
$(window).off("scroll");
} else {
// do nothing
}
});
function checkVisible(elm, eval) {
eval = eval || "object visible";
var viewportHeight = $(window).height(),
scrolltop = $(window).scrollTop(),
y = $(elm).offset().top,
elementHeight = $(elm).height();
if (eval == "object visible")
return (
y < viewportHeight + scrolltop && y > scrolltop - elementHeight
);
if (eval == "above") return y < viewportHeight + scrolltop;
}
the second part, works with jquery, but should be in JavaScript only
how can i do it, many thanks
here’s working with jquery, but i want in javascript
https://jsfiddle.net/larico/s9omLp6a/5/