How to call a function on mouse scroll wheel via jquery?
How to call a function on mouse scroll wheel via jquery?
Simple copy and paste this code and follow the steps.
<script>
function handle(delta) {
if (delta < 0)
{
functionscrolldown(); // You can change here the function event according to your need on mouse wheel down
}
else
{
functionscrollup(); // You can change here the function event according to your need on mouse wheel up
}
}
/** Event handler for mouse wheel event.
*/
/* here mouse wheel event stop from the browser */
$(document).on("click", '.fancybox-close', function(e) { // you also need to stop the Mouse wheel function event on a certain evernt of mouse click so you need to change the ".fancybox-close" class accoding to your click button
window.removeEventListener('DOMMouseScroll', wheel, false);
window.removeEventListener('mousewheel', wheel, false);
});
/* here mouse wheel event will start for the browser */
$(document).on("click", '.fancybox-button', function(e) { // Mouse wheel function will run on click on a certain evernt of mouse click so you need to change the ".fancybox-button" class accoding to your click button
if (navigator.userAgent.toLowerCase().indexOf('firefox') >= 0) {
window.addEventListener('DOMMouseScroll', wheel, false); // For Firefox
}else
{
window.addEventListener('mousewheel', wheel, false); // Chrome/Safari/IE9/Opera
}
});
/* function will check the wheel event */
function wheel(event){
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
} else if (event.detail) { /** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail/3;
}
/** If delta is nonzero, handle it.
* Basically, delta is now positive if wheel was scrolled up,
* and negative, if wheel was scrolled down.
*/
if (delta)
handle(delta);
/** Prevent default actions caused by mouse wheel.
* That might be ugly, but we handle scrolls somehow
* anyway, so don't bother here..
*/
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
</script>
Simple copy and paste this code and follow the steps.
<script>
function handle(delta) {
if (delta < 0)
{
functionscrolldown(); // You can change here the function event according to your need on mouse wheel down
}
else
{
functionscrollup(); // You can change here the function event according to your need on mouse wheel up
}
}
/** Event handler for mouse wheel event.
*/
/* here mouse wheel event stop from the browser */
$(document).on("click", '.fancybox-close', function(e) { // you also need to stop the Mouse wheel function event on a certain evernt of mouse click so you need to change the ".fancybox-close" class accoding to your click button
window.removeEventListener('DOMMouseScroll', wheel, false);
window.removeEventListener('mousewheel', wheel, false);
});
/* here mouse wheel event will start for the browser */
$(document).on("click", '.fancybox-button', function(e) { // Mouse wheel function will run on click on a certain evernt of mouse click so you need to change the ".fancybox-button" class accoding to your click button
if (navigator.userAgent.toLowerCase().indexOf('firefox') >= 0) {
window.addEventListener('DOMMouseScroll', wheel, false); // For Firefox
}else
{
window.addEventListener('mousewheel', wheel, false); // Chrome/Safari/IE9/Opera
}
});
/* function will check the wheel event */
function wheel(event){
var delta = 0;
if (!event) /* For IE. */
event = window.event;
if (event.wheelDelta) { /* IE/Opera. */
delta = event.wheelDelta/120;
} else if (event.detail) { /** Mozilla case. */
/** In Mozilla, sign of delta is different than in IE.
* Also, delta is multiple of 3.
*/
delta = -event.detail/3;
}
/** If delta is nonzero, handle it.
* Basically, delta is now positive if wheel was scrolled up,
* and negative, if wheel was scrolled down.
*/
if (delta)
handle(delta);
/** Prevent default actions caused by mouse wheel.
* That might be ugly, but we handle scrolls somehow
* anyway, so don't bother here..
*/
if (event.preventDefault)
event.preventDefault();
event.returnValue = false;
}
</script>
Comments
Post a Comment