How to prevent fixed button from overlapping footer area and stop the button on top of where the footer is located

前端 未结 3 1102
我寻月下人不归
我寻月下人不归 2021-01-06 18:47

I am trying to create a button that is fixed on the lower-left side of the screen. I tried to setup in JSFiddle to recreate what I\'m trying to do.

Here is my HTML:<

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 18:56

    I was looking for something similar and couldn't find any suitable answer here is what I came up with.

    var $fixed_element = $(".some_element")
    if($fixed_element.length){
            var $offset = $(".footer").position().top,
                $wh = $(window).innerHeight(),
                $diff = $offset - $wh,
                $scrolled = $(window).scrollTop();
            $fixed_element.css("bottom", Math.max(0, $scrolled-$diff));
        }
    

    So now the fixed element would stop right before footer. and will not overlap with it.

提交回复
热议问题