Solved

$(window).scroll - Is it bad?

Posted on 2013-06-17
6
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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)
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…

751 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