鍍金池/ 問答/PHP  HTML/ 列表左邊固定,右邊滾動,下拉后側消失求解決

列表左邊固定,右邊滾動,下拉后側消失求解決

左邊固定,右邊滾動,剛開始沒有問題。左側列表太短,下拉后會出現整個右側消失。代碼如下:
// 左邊固定,右邊滾動

function myscoll(){
    var fixedEle = $('#news-right');
    var fixedEleTop = fixedEle.offset().top;
    var winHeight = $(window).height();
    var winWidth = $(window).width();
    $(window).scroll(function(e){
        var footerTop = $('#footer').offset().top-winHeight; // 滾動條滾動多少,底部出現
        _scrollTop = $(document).scrollTop();   

        if(_scrollTop > fixedEleTop+10 &&  _scrollTop<= footerTop){
            fixedEle.css({
                position: 'fixed',
                top: '-850px',
                right: (winWidth - 1144)/2+'px',
            });              
        }else if( _scrollTop>footerTop){
            var a = _scrollTop-footerTop;
            fixedEle.css({
                'position': 'fixed',
                'top':'-'+(850+a)+'px',
                'right': (winWidth - 1144)/2+'px',
            });
        }else{
            fixedEle.css({
                'position': '',
            }); ;
        }
    })
}

$(window).bind('load',function(){
    window.setTimeout(myscoll, 500);
});

圖片描述

圖片描述

回答
編輯回答
柒喵

clipboard.png

2017年1月26日 11:16
編輯回答
筱饞貓

當你設置position為空時,

fixedEle.css({
    'position': '',
});

將去掉添加在#news-right DOM元素style屬性上的position值,將其恢復為class屬性或css文件中指定的#news-right 的position值

你可以通過瀏覽器開發(fā)者工具查看對應DOM元素當前的CSS樣式值

2018年8月4日 15:59
編輯回答
遺莣

問題已解決了,謝謝

2017年4月7日 08:52