user2252219
user2252219

Reputation: 865

Make script start at the top of a specific div

So I basically want the script to start at the top of "mini" div but can't get it to work right.
enter image description here

#mini {
width: 100%;
padding-top: 300px;}

var tTop = $("#mini").outerHeight(true);

Full script:

$(window).scroll(checkY);

    function checkY() {
        //save this value so we dont have to call the function everytime
        var top = $(window).scrollTop();
        $(".title").each(function () {
            var target = $(this).closest(".content");
           var tTop = $("#mini").outerHeight(true);
            var tBottom = target.offset().top + target.outerHeight();
            if (top >= tTop && top <= tBottom) {
                console.log("Show");
                $(this).show();
            } else {
                console.log("Hide");
                $(this).hide();
            }
        });
    }
    checkY();

Upvotes: 0

Views: 74

Answers (1)

CodeWizard
CodeWizard

Reputation: 142114

Why not setting the mini style to

position:relative;

and the inner div to

position: absolute;  
top:0

Upvotes: 1

Related Questions