Scroll to the top of the page using JavaScript?

后端 未结 30 1450
借酒劲吻你
借酒劲吻你 2020-11-22 03:18

How do I scroll to the top of the page using JavaScript? The scrollbar instantly jumping to the top of the page is desirable too as I\'m not looking to achieve smooth scroll

30条回答
  •  春和景丽
    2020-11-22 03:37

    With window.scrollTo(0, 0); is very fast
    so i tried the Mark Ursino example, but in Chrome nothing happens
    and i found this

    $('.showPeriodMsgPopup').click(function(){
        //window.scrollTo(0, 0);
        $('html').animate({scrollTop:0}, 'slow');//IE, FF
        $('body').animate({scrollTop:0}, 'slow');//chrome, don't know if Safari works
        $('.popupPeriod').fadeIn(1000, function(){
            setTimeout(function(){$('.popupPeriod').fadeOut(2000);}, 3000);
        });
    });
    

    tested all 3 browsers and it works
    i'm using blueprint css
    this is when a client clicks "Book now" button and doesn't have the rental period selected, slowly moves to the top where the calendars are and opens a dialog div pointing to the 2 fields, after 3sec it fades

提交回复
热议问题