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

前端 未结 2 1805
再見小時候
再見小時候 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);
    }
    
    0 讨论(0)
  • 2020-12-14 04:59

    Quick demo here

    Basically all you need is

     $('html, body').animate({ 
          scrollTop: $('#yourDiv').offset().top 
      }, 3000); 
    
    0 讨论(0)
提交回复
热议问题