jQuery cross-browser “scroll to top”, with animation

前端 未结 8 945
难免孤独
难免孤独 2020-12-09 09:32

Right now I\'m using this:

$(\'#go-to-top\').each(function(){
  $(this).click(function(){ 
    $(\'html\').animate({ scrollTop: 0 }, \'slow\'); return true;          


        
8条回答
  •  难免孤独
    2020-12-09 09:42

    I am using this, This is also simple

    $(document).ready(function(e) {
    var a = 400,
    t = 1200,
    l = 700,
    s = e(".scrool-top");
    e(window).scroll(function() {
    e(this).scrollTop() > a ? s.addClass("scrool-is-visible") : s.removeClass("scrool-is-visible scrool-fade-out"), e(this).scrollTop() > t && s.addClass("scrool-fade-out")
    }), s.on("click", function(a) {
    a.preventDefault(), e("body,html").animate({
    scrollTop: 0
    }, l)
    })
    })
    

提交回复
热议问题