Jquery animation problem

Hello experts,

this is the site I develope - goo.gl/YCMS3q .

Q: Why the navigation menu on mobile devices doesn't scroll right?
* On desktops it's ok [don't look at styling on desktop- it's not done yet]

This is the JS:
$(function() {
	var nav = $('.nav');
	var navLiA = $('.nav>ul>li>a');
	var collapse = $('#collapse');
	var collapsedSpan = $('#collapse > span');

	
	//full-screen bg
	fullHeightBg('.header');
	$(window).on('resize', function() {
		fullHeightBg('.header');
	});
	
	//hamburger button menu
	$(collapse).on('click', function() {
		$(nav).toggle();
		$(collapsedSpan).toggleClass('fa-bars fa-close');
	});
	$(navLiA).on('click', function(e) {
		e.preventDefault;

        var scrollAnchor = $(this).attr('href');
        var scrollPoint  = $(scrollAnchor).offset().top;

        $('html, body').animate({
            scrollTop : scrollPoint
        }, 700);

		if (collapse.is(":visible") ) {
			$(nav).hide();
			$(collapsedSpan).removeClass('fa-close').addClass('fa-bars');
		}
	});
});

Open in new window

LVL 1
Fajer39Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
What are we looking for - seems to work fine here.
0
Fajer39Author Commented:
Please try to click couple of time to the navigation links without refreshing on mobile devices.

IOS 8.4- Safari,- when click on contact- it scrolls to the wrong coordinates.

Android 4.3 - It's like the "final destination" of the scroll is shown right after the click(overlays the header) for like 100ms, then it disappears and then the scroll start.
EDIT: The problem from android actually happens on all devices- it was just so fast that I didn't noticed it at first
0
Julian HansenCommented:
Nope - seems to work fine for me scrolls to the right place every time.

Do you see the same thing happening here http://mobiletest.me/?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Fajer39Author Commented:
I tried it on the real phones, not emulators...The problem is that in chrome dev tools, everything is fine too, but on the actual device...it's not the case...it's ok on the http://mobiletest.me/ but that's not keeping me calm because my girlfriend's iphone 5 and my galaxy s4 still don't work right with this features
0
Julian HansenCommented:
Going to be difficult to debug then.

Try disabling different scripts on your page and see if that makes a difference.
0
Fajer39Author Commented:
So the problem was with the script...which was obvious to me from the beggining since it didn't work across all devices...I really don't know how you've tested it. But anyway, I've solved it myself. I found this code snippet which I edited to suit for my needs and it works like a charm:

$('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        || location.hostname == this.hostname) {

        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
           if (target.length) {
             $('html,body').animate({
                 scrollTop: target.offset().top
            }, 1000);
            return false;
        }
    }
});

Open in new window


So I hope It helps other people as well.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fajer39Author Commented:
self-explanatory
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.