2

http://jqueryfordesigners.com/demo/scroll-link-nav.html

The link above is more or less what im looking for in terms of the active state responding to the scroll position.

But if one tries this on an ipad the active state sticks in certain places and trying to navigate purely by tapping the buttons, it stops scrolling after the first tap.

Anyone know any fixes for this for the ipad issues?

1
  • I've given a solution, let me know what you think. May 22, 2012 at 18:20

2 Answers 2

1

I have one solution which does the scrolling on all browsers

http://jsfiddle.net/t9mna/1/ all browsers

$("nav ul li a").click(function(){
   $(".selected").removeClass("selected");
    $(this).addClass("selected");
    var $scrollTo = $($(this).attr("href"));
    $('html, body').animate({
    scrollTop: $scrollTo.offset().top
    }, 500);
});

​and another for just iPad, i don't have an iPad so i personally can't test it so let me know how it goes

http://jsfiddle.net/t9mna/3/ just for iPad //not been tested by me

function isiPad() {
    return navigator.userAgent.match(/iPad/i); 
}


    $("nav ul li a").click(function(){
       $(".selected").removeClass("selected");
        $(this).addClass("selected");
        var $scrollTo = $($(this).attr("href"));
        $(function() {
        if ($(isiPad).length != 1) {
        $('html, body').animate({
        scrollTop: $scrollTo.offset().top
        }, 500);
    }
    });
    });​
4
  • Hi Yusaf, thanks for the response. I've tested both and neither seem to work on the ipad if the user wants to navigate purely from tapping the buttons on the left. I've also noticed these two examples don't update the selected class when the scroll is moved, where as they do on the original link sent in the question. I've read the ipad moves the selected content to the back once the screen is tapped, is there a way to disable this maybe? May 23, 2012 at 15:07
  • I don't have a clue to be honest, i have never used nav or section EVER, so....there may be another issue with it though, being the anchor. try the html without any of the jQuery ( jsfiddle.net/t9mna/4 ) let me know if the scrolling still works.... May 23, 2012 at 16:37
  • Still no joy unfortunately, i'll post back if i find anything, cheers dude. May 24, 2012 at 9:02
  • try jsfiddle.net/t9mna/5 it's all i can think that could resolve the problem May 24, 2012 at 19:12
0
    $("nav ul li a").click(function(){
    $(".selected").removeClass("selected");
    $(this).addClass("selected");
    var $scrollTo = $($(this).attr("href"));
    $(function() {
        if ($(isiPad).length != 1) {
            $('html, body').animate({
                scrollTop: $.scrollTo.offset().top //point 
            }, 500);
        }
    });
});​

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.