天天看点

位置超出高度时就固定在下方的样式

商城结算按钮样式,情况如下:

位置超出高度时就固定在下方的样式
$.fn.smartFloatBottom = function() {
        let position = function(element) {
            let top = element.position().top,
                height = element.height(),
                pos = element.css("position"),
                wh = window.innerHeight;
            if(wh  < top + height){
                element.css({
                    position: "fixed",
                    bottom: 0
                });
            }
            $(window).scroll(function() {
                let scrolls = $(this).scrollTop();
                if (scrolls + wh  < top + height) {
                    element.css({
                        position: "fixed",
                        bottom: 0
                    });
                }else {
                    element.css({
                        position: pos
                    });
                }
            });
        };
        return $(this).each(function() {
            position($(this));
        });
    };

    $(".FloatBarHolder").smartFloatBottom();
           

继续阅读