Disable scroll on thum list - javascript

I am creating a slider based on master slider I want to remove scroll event on thumb-list so that user can not scroll thumb list .I checked all the option in admin site but not working and no option for stop thumb scroll.I also tried jquery but not succeed any help should be appreciated I want to stop scroll only on the thumb list not whole body.
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;
}
disableScroll();

Try using this css it will block scrolling
body, html {
overflow-x: hidden;
overflow-y: auto;
}

Related

Ionic 2 - How do I disable scrolling

First of all: I know there are some topics about this already, but none of them seem to help me.
I tried all methods I could find to disable scrolling on one of my pages, but none of them work and so I come to seek help here.
What I tried:
Creating a css class which hides overflow (same with attr.noScroll)
setScrollDisabled
set a div as ion-fixed
ion-content no-bounce
::-webkit-scrollbar
overflow-scroll="false"
This is what my page looks like ...
It has this white bar on the bottom of the screen when I scroll down
I only added a background picture whose width I set to 100% and height:auto (height: 100% produces the same white bar)
For reference, here is my code if it helps
<ion-content>
<img class="bgc" src="assets/background.png">
</ion-content>
The scroll event cannot be canceled. But you can do it by canceling these interaction events:
Mouse & Touch scroll and Buttons associated with scrolling.
http://output.jsbin.com/xatidu/4/ <-- Working version
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;
}
To fix it, you should understand what's causing it, so you probably want to read this.
In some special cases, you might be able to hide that white space by disabling scrolling, but that's really not how you should approach this issue.
Instead, you should just remove the white space. You can do it by applying
display: block;
... or ...
float: left;
width: 100%;
height: auto;
to your <img> element.
As an alternative, you can change your markup to:
<ion-content>
<img class="bgc" src="assets/background.png"
/></ion-content>

Scroll to specific div when scroll down or scroll up

On my site I have it so my scroll is locked:
body {
overflow: hidden;
height: 100%;
}
and on click of buttons it scrolls to a certain div, all the divs are beneath each other, I would like to know if it is possible to check if the user 'tries' to scroll down or up, while scroll is locked, so if they try scroll down with the mouse wheel, I want to know how to do this so I can scroll down or up to the next div.
Any help is appreciated.
This will tell you if they are scrolling down or up. Then you would have to deal with the transition by yourself.
But in any case, if you are looking for a more tested solution, I would encourage you to use an already existent plugin such as fullPage.js which will provide old browser compatibility, touch detection, a proper solution for trackpads and Apple laptops/Magic Mouse, resize support and a lot of other useful features.
addMouseWheelHandler();
function MouseWheelHandler(e) {
// cross-browser wheel delta
e = window.event || e;
var value = e.wheelDelta || -e.deltaY || -e.detail;
var delta = Math.max(-1, Math.min(1, value));
//scrolling down?
if (delta < 0) {
console.log("scrolling down");
}
//scrolling up?
else {
console.log("scrolling up");
}
return false;
}
function addMouseWheelHandler() {
if (document.addEventListener) {
document.addEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
document.addEventListener('wheel', MouseWheelHandler, false); //Firefox
} else {
document.attachEvent('onmousewheel', MouseWheelHandler); //IE 6/7/8
}
}

CSS scrolling issue in mobile phone

I have been trying to solve this weird problem with scrolling in my website. The scrolling works fine when viewed on a Desktop Computer. However, it doesn't work in mobile phones. Do, I need to use some javascript to solve this issue?Or, can it be done just with CSS.
Here is my CSS snippet :
#popup-div{
height: 100%;
overflow:scroll;
}
function isTouchDevice(){
try{
document.createEvent("TouchEvent");
return true;
}catch(e){
return false;
}
}
function touchScroll(id){
if(isTouchDevice()){ //if touch events exist...
var el=document.getElementById(id);
var scrollStartPos=0;
document.getElementById(id).addEventListener("touchstart", function(event) {
scrollStartPos=this.scrollTop+event.touches[0].pageY;
event.preventDefault();
},false);
document.getElementById(id).addEventListener("touchmove", function(event) {
this.scrollTop=scrollStartPos-event.touches[0].pageY;
event.preventDefault();
},false);
}
}
//On page load
touchScroll('popup-div');
Chris has shown a best working example
http://chrismbarr.github.io/TouchScroll/

Cross-browser enabling/disabling mouse scroll wheel

I have 2 button: "disable_scroll" and "enable_scroll" for enabling/disabling mouse scroll.
Disabling scroll works well:
var cancelscroll = function(e) {
e.preventDefault();
};
$("#disable_scroll").on("click", function () {
if ("onmousewheel" in document) { // for browser except FF
document.onmousewheel = cancelscroll;
} else { // for FF
document.addEventListener('DOMMouseScroll', cancelscroll);
}
});
but when I want to enable mouse scroll, I have problems in Firefox. In Firefox, the mouse scroll won't turn on (in other browsers, this code works well). Please can anyone help locate the error?
$("#enable_scroll").on("click", function () {
if ("onmousewheel" in document) { // for brouzers except FF
document.onmousewheel = function(e){};
} else { // for FF
document.addEventListener('DOMMouseScroll', function(e){});
}
});
This works everywhere: https://github.com/brandonaaron/jquery-mousewheel/blob/master/jquery.mousewheel.js
You use it like this:
$('#test3')
.hover(function() { log('#test3: mouseover'); }, function() { log('#test3: mouseout'); })
.mousewheel(function(event, delta, deltaX, deltaY) {
log('#test3: I should not have been logged');
})
.unmousewheel();

how do i prevent scroll down in javascript?

ok... I might be a lazy one to search but it is a bit annoying that all I can find is
"how can i set scroll down event" when I searched "how do i prevent scroll down".
in my javascript code, I set event for down arrow key. When I press down arrow
from the browser, the browser not only does an event I set, but also does
scrolling down the page which is not I intended to. So here is my question.
How can I disable scroll down function which occurs when I press down arrow?
any help will be appreciated.
If you want to prevent the vertical scrollbar and any vertical scrolling action by the user, you can use this javascript:
document.body.style.overflowY = "hidden";​
Or, this can also be set with a CSS rule:
body {overflow-y: hidden;}
On the other hand, if what you're trying to do is to prevent the default key handler for the down arrow from doing anything after you process the down array, then you need to call e.preventDefault() like this:
function myKeyDownHandler(e) {
// your code here
e = e || window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false; // older versions of IE (yuck)
}
return false;
}
A cleaner way if you need to do this in more than one place would be to make your own cross browser function for this:
function preventDefault(e) {
e = e || window.event;
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false; // older versions of IE (yuck)
}
}
function myKeyDownHandler(e) {
// your code here
preventDefault(e);
return false;
}
This is one of those perfect examples where a cross-browser framework (jQuery/YUI/etc) saves you time because they've already done all this cross-browser work for you.
Here's an interesting article on preventDefault and stopPropagation().
Here is an example page that doesn't allow for the use of the arrow keys for scrolling:
<script>
document.onkeydown = function(evt) {
evt = evt || window.event;
var keyCode = evt.keyCode;
if (keyCode >= 37 && keyCode <= 40) {
return false;
}
};
</script>
<body style="height:3000px;">
</body>

Categories

Resources