如果超过其他元素则隐藏

时间:2012-06-21 14:51:11

标签: jquery

我在另一个div中有一个固定位置的div,它跨越页面折叠。现在,还有其他元素也包含父div,主要位于页面顶部。我想隐藏具有固定位置的孩子,如果它恰好位于该父母中的另一个元素上,例如,如果用户调整窗口大小。我怎么能用jQuery做到这一点?

这是我到目前为止所得到的:

JS

$(function(){
    function floatingDiv(){
        var m = $('#parentDiv'), offset = m.offset(), posL = Math.floor(offset.left - 15);
        $('#divFloat').remove();
        m.append(\"<div id='divFloat' style='position:fixed;left:\"+ posL +\"px; bottom:55px; border:0'><a href='/' style='width:168px;height:43px; background: url(/i/free3day.png) no-repeat center center;position:fixed; border:0; left:\"+ posL +\"px;bottom:55px'></a></div>\");
    }

    floatingDiv();

    $(window).resize(function(){
        floatingDiv();
    });
});

HTML

<div id="parentDiv">
    <a href="#">SOME LINK</a>
    <div>some content</div>
</div>

0 个答案:

没有答案
相关问题