Chrome on Win7 not disabling scroll
Opened this issue · 0 comments
panfanky commented
I've just had a problem in Chrome on win7 - scrollbar was showing and page was scrolling when inside swipebox. Tested also on swipebox hp, the same.
Here is my workaround to prevent it
/*---------------------------*/
/*disable scroll script from https://stackoverflow.com/questions/4770025/how-to-disable-scrolling-temporarily */
// left: 37, up: 38, right: 39, down: 40,
// spacebar: 32, pageup: 33, pagedown: 34, end: 35, home: 36
var keys = {37: 1, 38: 1, 39: 1, 40: 1};
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault)
e.preventDefault();
e.returnValue = false;
}
function preventDefaultForScrollKeys(e) {
if (keys[e.keyCode]) {
preventDefault(e);
return false;
}
}
function disableScroll() {
if (window.addEventListener) // older FF
window.addEventListener('DOMMouseScroll', preventDefault, false);
window.onwheel = preventDefault; // modern standard
window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
window.ontouchmove = preventDefault; // mobile
document.onkeydown = preventDefaultForScrollKeys;
}
function enableScroll() {
if (window.removeEventListener)
window.removeEventListener('DOMMouseScroll', preventDefault, false);
window.onmousewheel = document.onmousewheel = null;
window.onwheel = null;
window.ontouchmove = null;
document.onkeydown = null;
}
/*-----------------------------*/
/*calling swipebox with callbacks*/
$(document).ready(function(){
$( '.swipebox' ).swipebox( {
beforeOpen: function() {
$("body").css({'overflow':'hidden'});
$("body::-webkit-scrollbar").css({'width':0,'background-color':'transparent'});
disableScroll();
},
afterClose: function() {
$("body").css({'overflow':'none'});
$("body::-webkit-scrollbar").css({'width':'auto','background-color':''});
enableScroll();
}
} );
});