让脚本从特定div的顶部开始

时间:2014-07-16 00:42:10

标签: javascript jquery html css

所以我基本上希望脚本从“迷你”div的顶部开始,但无法让它正常工作 enter image description here

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

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

完整脚本:

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

1 个答案:

答案 0 :(得分:1)

为什么不将迷你风格设置为

position:relative;

和内部div

position: absolute;  
top:0