Prevent page from scrolling to top

Hello,

i need some help with some javascript and or jquery that can prevent users form scrolling to the very top of my web page i need the top to always stop at about 74pixels
LVL 1
Chris JonesLead Application Web DeveloperAsked:
Who is Participating?
 
Tom BeckCommented:
I'm probably missing the point too. If users cannot scroll to the top of the page then is the top 74px hidden from view at all times? Maybe a negative top margin on the body (although I cannot imagine why you would want this).

body {
   margin-top: -74px
}

Or do you mean the top is visible on initial load but once the user scrolls, they cannot scroll back high enough to see the top 74 pixels?
$(document).ready(function(){
	$(window).on('scroll', function(){
		if ($(this).scrollTop() > 74) {
			$('body').css('margin-top', '-74px');
		}
	});
});

Open in new window

0
 
plusone3055Commented:
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
i am not sure if this will work the user can scroll with there mouse i need some java to set the boundaries maybe so the user cant scroll to the very top.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Chris JonesLead Application Web DeveloperAuthor Commented:
just an update i did try the code and i could still scroll to the top.
0
 
plusone3055Commented:
sorry my bad :(
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
your exampled worked that's what i was trying to achieve the header has a slight issue when it scrolls back so a stop gap prevent from scrolling to the very top.
0
 
Tom BeckCommented:
Not clear. Is there a question or was that just an update?
0
 
Chris JonesLead Application Web DeveloperAuthor Commented:
this was just an update
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.