Minus a few pixels from jQuery height()

后端 未结 4 1344
旧时难觅i
旧时难觅i 2021-01-29 15:35

Ok, amateur question here but im really bumping my head.

Using the jQuery below, i would like to add margin-top:-100px; to the height value.

Please help! Thanks

4条回答
  •  野的像风
    2021-01-29 16:21

    If you already have margin-top of -100px assigned to some element like #home, then You can try this

    $(function () {
    function HomePageSize() {
    $('#home').css({
        width: $(window).width(),
        height:  $(window).height() + parseInt($("#home").css("margin-top"))
    });
    }
    $(window).resize(function () {
     HomePageSize();
    });
     HomePageSize();
    });
    

提交回复
热议问题