$(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.
LVL 58
GaryAsked:
Who is Participating?
 
wellholeConnect With a Mentor Commented:
In my opinion, the experience is much more important. If immediacy adds to that experience, I would recommend that method. However, if immediacy detriments from that experience on older machines that'll be using your website, you may want to reconsider. I assume that you're trying to keep something on the screen by catching the scroll event - Have you considered using fixed positioning?
0
 
GaryAuthor Commented:
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.
0
 
GaryAuthor Commented:
You can see it in action here
Its the small side bar on the left
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
COBOLdinosaurConnect With a Mentor Commented:
If you are concerned about the cost of the scroll; why not just make it position:fixed with the top offset value the same as the height of the header and just let it stay at one position. It will still be well above the fold and visible.  Then you don't need any scripting to manage it.

Cd&
0
 
GaryAuthor Commented:
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)
0
 
GaryAuthor Commented:
I'll stick with the user experience
0
All Courses

From novice to tech pro — start learning today.