Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
42
rated 0 times [  44] [ 2]  / answers: 1 / hits: 90546  / 11 Years ago, sun, may 19, 2013, 12:00:00

I want to disable scrolling for my webpage, but completely, not just disable scrollbars so



overflow: hidden


will not work.



Also this workaround does not apply on Macs due to the soft-scroll on edges. It will show a terrible shaky animation:



window.onscroll = function () {
window.scrollTo(0,0);
}


Is there any other method to disable scrolling completely?


More From » html

 Answers
3

Presuming the simplified HTML code is:



<html><body><div class=wrap>content...</div></body></html>


Set both body, html to height:100%;



body, html {height:100%;}


Put a div inside body, and set it to stretch across all the body height:



div.wrap {height:100%; overflow:hidden;}


This will prevent window from scrolling in weird ways, like, pressing mouse wheel and moving it, using anchors, etc.



To remove the scroll bar itself (visually), you should also add:



body {overflow: hidden; }





To disable scrolling via pressing arrow keys on keyboard:



window.addEventListener(keydown, function(e) {
// space, page up, page down and arrow keys:
if([32, 33, 34, 37, 38, 39, 40].indexOf(e.keyCode) > -1) {
e.preventDefault();
}
}, false);

[#78137] Friday, May 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
vanessag

Total Points: 170
Total Questions: 98
Total Answers: 88

Location: El Salvador
Member since Sun, Sep 12, 2021
3 Years ago
;