Link to home
Start Free TrialLog in
Avatar of Gary
GaryFlag for Ireland

asked on

$(window).scroll - Is it bad?

Catching the scroll event is there anything to watch for?
Is it bad to keep capturing it?
CPU seems to jump about 15-20% while capturing.
Is it better to have a timeout? I have tried it with a timeout and the cpu didn't jump as much and obviously only fires after the scroll has finished but I lose a bit of the immediacy of the event.
But doing a constant scroll up and down without stopping uses more cpu with the timeout but less if I just keep capturing it.
Or am I worried about nothing.
ASKER CERTIFIED SOLUTION
Avatar of wellhole
wellhole

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary

ASKER

Yes, trying to keep an element in position with scroll.
It is using fixed position where the scroll is above 130 but where the scroll is less than 130 I want to keep it below the header that's why I'm checking the scroll position.
After more testing there doesn't seem to be much difference in cpu between the two methods.
I'll leave it open a while longer in case anyone else has more to add.
Avatar of Gary

ASKER

You can see it in action here
Its the small side bar on the left
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary

ASKER

Because on mobile, especially in landscape, it would be mostly below the viewport.
(Even though I've just noticed it's not working properly on the iphone anyway)
Avatar of Gary

ASKER

I'll stick with the user experience