天天看點

位置超出高度時就固定在下方的樣式

商城結算按鈕樣式,情況如下:

位置超出高度時就固定在下方的樣式
$.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();
           

繼續閱讀