scroll to next divs on mousewheel jQuery

你离开我真会死。 提交于 2019-12-04 15:08:45
Vixed

This should work: https://jsfiddle.net/jtpbq9zf/

Refer to event.wheelDelta returns undefined for event.originalEvent.wheelDelta

$(function(){
  $('section').css({'height':(($(window).height()))+'px'});
  // Now bind the event to the desired element
  $('section').on('mousewheel', function(e){
    e.preventDefault();
    if(e.originalEvent.wheelDelta < 0) {
      if (!$(this).is(':last-child'))
        $('body').scrollTop($(this).next().offset().top);
    } else {
      if (!$(this).is(':first-child'))
        $('body').scrollTop($(this).prev().offset().top);
      }
  });
  $(window).resize(function(){ // On resize
      $('section').css({'height':(($(window).height()))+'px'});
  });
});

Smooth version

Just replace $('body').scrollTop($(this).next().offset().top);

with $('body').animate({scrollTop:$(this).next().offset().top}, '700');

..of course look at prev() and next() elements.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!