Solved

$(window).scroll - Is it bad?

Posted on 2013-06-17
6
264 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
Comment Utility
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
Comment Utility
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
Comment Utility
You can see it in action here
Its the small side bar on the left
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I'll stick with the user experience
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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)

772 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