In JQuery is there way for slideDown() method to scroll the page down too?

前端 未结 2 1806
再見小時候
再見小時候 2020-12-14 04:15

The slideDown applied to a div does the slideDown but doesn\'t scroll the page down and the div slided down div remains hidden from view. Is there a way to scroll the page d

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 04:46

    $.extend($.expr[':'],{
        inView: function(a) {
            var st = (document.documentElement.scrollTop || document.body.scrollTop),
                ot = $(a).offset().top,
                wh = (window.innerHeight && window.innerHeight < $(window).height()) ? window.innerHeight : $(window).height();
            return ot > st && ($(a).height() + ot) < (st + wh);
        }
    });
    
    if ($('#whatever').is(':not(:inView)')) {
        $('html,body').animate({ 
             scrollTop: $('#whatever').offset().top 
        }, 3000);
    }
    

提交回复
热议问题