Solved

$(window).scroll - Is it bad?

Posted on 2013-06-17
6
266 Views
Last Modified: 2013-06-24
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.
0
Comment
Question by:Gary
  • 4
6 Comments
 
LVL 9

Accepted Solution

by:
wellhole earned 350 total points
ID: 39253404
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
 
LVL 58

Author Comment

by:Gary
ID: 39253658
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
 
LVL 58

Author Comment

by:Gary
ID: 39253680
You can see it in action here
Its the small side bar on the left
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 150 total points
ID: 39253980
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
 
LVL 58

Author Comment

by:Gary
ID: 39254021
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
 
LVL 58

Author Closing Comment

by:Gary
ID: 39273431
I'll stick with the user experience
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now