简体   繁体   中英

Scroll to top Jquery not working

So I've been looking all over for this and the only thing that worked was to replace in CSS of the body height: 100% for min-height: 100% . The thing is that change breaks the styling of the page. Is there another workaround for this?

function ScrollTop() {
    $('html, body').animate({ scrollTop: 0 }, 0);
    return false;
}

function NextPage(page) {
    $(".page[data-page='" + page + "']").addClass("hidden");
    page = page + 1;
    $(".page[data-page='" + page + "']").removeClass("hidden");
    ScrollTop();
}
html, body, form, #container, #mainform, #content {
    margin: 0 auto;
    padding: 0;
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
}

Just FYI this is not working in any browser (latest version of all browsers to date). Also try removing overflow-x: hidden from the body and still wasn't working. Also tried

$("#container").animate({
    scrollTop:0
}, "slow");

window.scrollTo(0, 0) //this returns undefined

I have created a working fiddle. It is working just fine.

$(function() {
   $('.backtotop').click(function() 
        $('body').animate({ scrollTop: 0 }, .2);
        return false;
   });
});

This should work https://jsfiddle.net/cmhLroe1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM