Sunday, September 11, 2016

Sliding on mobile issue

1 comment

When I slide down / up on my website, on mobile, the first slide is buggy, looks like it slides in the right direction and then come back a few px to the other direction (but only the first slide in new direction). I think the better thing is to test it on a mobile phone: https://even-mind.com

How can I fix it? I hope you can help me guys!

(tested on iphone 5)

3 Answers

Answers 1

By looking in your DOM elements inspector you can find out that while scrolling down the position of the header changes from absolute to fixed and maybe this is what causes the issue.

This is the header before scrolling:

<div id="header" class="header"> 

and after scrolling:

<div id="header" class="header header-fixed header-prepare"> 

Try to change the HTML and give your header a fixed position from the start:

<div id="header" class="header header-fixed"> 

Answers 2

Well, I see the buggy/laggy scroll when I reach the "WE ARE" slide.

It might be that the animations of the fadingIn texts start from there and that makes it buggy, my recommendations are:

1- move all your <link> and <script> tags at the bottom of your HTML, just after the </body> to let the browser load the HTML elements first then the links and scripts.

2- Consider removing any unnecessary animations, scripts, links, etc. For example, I don't see the point of these fadeIn animations on all of the text. If you have them just to make the website fancy looking not a problem, but I recommend using animations just for user-experience performance. Example: Use the fadeIn or any type of animation on a specific element that you want the user to see. The animation makes the eyes pay attention to it and the user will look at the animation right away and pays attention the info.

3- As always, minify/compress your scripts, CSS, and images.

4- G-zip

5- Use GTmetrix.com to see everything wrong with your website

I will look at your code more and see if there are any code problems.

Edit:

Look here: https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Feven-mind.com%2F&tab=mobile

And here: https://gtmetrix.com/reports/even-mind.com/uVHRlGCl

NOTE: Your website is 3.04MB in size, consider doing the above instructions + links instructions!!!

Answers 3

As you can see from the DevTools Timeline view, there are lots of red marks at the top. These indicates slow frames. Looking at screenshots, you can easily tell there's something nasty about scroll itself.

Looking a little deeper – there are 2 functions fired with scroll event:

  1. The first one, Function Call from polyfill.js, which delegates the function execution to requestAnimationFrame (which is good)
  2. The second one, Function Call to jQuery which executes function immediately.

Timeline view

What you can do to improve your scroll perf is delegating function 2 to requestAnimationFrame. In a simplest form you can go with something like this:

$(window).scroll(function() {   requestAnimationFrame(someFunctionUpdatingDOM); }) 

The other thing is variables caching. The function which is calculating header position traverse DOM every time it's invoked. Since DOM operations are quite expensive, it's better to avoid them if not necessary.

var $header = $('.header'); // traverse DOM once, cache variable for later use in function  function someFunctionUpdatingDOM() {   $header.addClass('something'); } 

One more thing I've noticed – there are scroll perf issues on desktop view too, caused by extensive repaints of the background image. This is caused by a script changing background-position to achieve parallax effect. It's generally better idea to use CSS transforms, like translate3d(), which are hardware accelerated. This way browsers can schedule layer (image) transformations to GPU, omitting unnecessary repaints, making the page scroll smoothly.

Good luck with the fixes!

If You Enjoyed This, Take 5 Seconds To Share It

1 comment: