Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Convert jquery to javascript - When i scroll down to specific area (Div ID) load HTML Content one time

javascript

#1

i have this code, When i scroll down to specific area (Div ID) load HTML Content one time.

Actually is working with jQuery, but i want in JavaScript only, without jQuery

$(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;
}

help please


#2

Hello, @xolito: This seems like a general programming question that is not specific to New Relic. You are welcome to post it our general discussion area, but you may have more success posting it to a general programming forum, such as Stack Overflow.