Minus a few pixels from jQuery height()

后端 未结 4 1342
旧时难觅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:16

    If I understand correctly this should do it:

    $(function () {
    function HomePageSize() {
        var winHeight = $(window).height(); // store height in variable
        var myMargin = winHeight - 100; // deduct 100 from height
    
        $('#home').css({
            width: $(window).width(),
            height: winHeight,
            marginTop: myMargin // assign calculated value to margin-top
        });
    }
    $(window).resize(function () {
        HomePageSize();
    });
    HomePageSize();
    });
    

提交回复
热议问题