Is there a way to trigger a scroll wheel event with an arbitrary delta. Just like jQuery does with \'click\' like:
$(\'#selector\').trigger(\'click\');
You can use the jquery scroll event and on call back u can do ur math. Please find the code snipet usefull.
//to make dummy paragraphs
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
$( "p" ).clone().appendTo( document.body );
//dummy paragraphs end here
//the below scroll() callback is triggered eachtime mouse wheel scroll happens
$( window ).scroll(function() { //i reference to window if u want u can iD a div and give div ID reference as well
console.log("scolling....");
//update with the delta u required.
});
<html lang="en">
<head>
<meta charset="utf-8">
<title>scroll demo</title>
<style>
div {
color: blue;
}
p {
color: green;
}
span {
color: red;
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div>Try scrolling the iframe.</div>
<p>Paragraph - <span>Scroll happened!</span></p>
</body>
</html>
I used this code in making my own scroll.
$('body').bind('mousewheel DOMMouseScroll', function(event) {
var delta = Math.max(-1, Math.min(1, (event.originalEvent.wheelDelta || -event.originalEvent.detail))) * -1;
}
I added * -1
to invert. you can remove it.
Try:
.trigger("mousewheel", {wheelDelta: 100})
(Completely untested. Inspired by Binding to the scroll wheel when over a div)