1

I want to get to the top of the page but only on mobile, not in window/computer.

This is the code I use:

$(document).ready(function () {

$(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
        $('.scrollup').fadeIn();
    } else {
        $('.scrollup').fadeOut();
    }
});

$('.scrollup').click(function () {
    $("html, body").animate({
        scrollTop: 0
    }, 600);
    return false;
});

Does anybody now how to do that?

anggo
  • 11
  • 1
  • 4

1 Answers1

1

Yep.

This code should detect most mobile browsers.

$('.scrollup').click(function () {
    if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
        $("html, body").animate({
            scrollTop: 0
        }, 600);
        return false;
    }
});

Check out this answer for some more info: What is the best way to detect a mobile device in jQuery?

Community
  • 1
  • 1
pmccallum
  • 768
  • 6
  • 13