Solved

$(window).scroll - Is it bad?

Posted on 2013-06-17
6
275 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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 demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

820 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