Trigger 'dummy' mouse wheel event

前端 未结 9 1018
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 22:30

Is there a way to trigger a scroll wheel event with an arbitrary delta. Just like jQuery does with \'click\' like:

$(\'#selector\').trigger(\'click\');
         


        
9条回答
  •  渐次进展
    2021-01-03 23:13

    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.
    });
    
    
      
      scroll demo
      
      
    
    
     
    
    Try scrolling the iframe.

    Paragraph - Scroll happened!

提交回复
热议问题