[英]How to execute a scroll command in jquery when what's being scrolled is within a fixed div set to overflow: scroll
[英]How to scroll to a specific div when the mouse is scrolled with jQuery?
我現在有了這段代碼,單擊按鈕時它會滾動到正確的位置:
$("#skills").click(function() {
$('html, body').animate({scrollTop: $("#skills_page").offset().top}, 500);
$(this).addClass("toggled_alt");
$("#skills_id").css("background-color", "#646464");
$("#contact_id, #home_id, #about_id").css("background-color", "transparent");
$("#home, #contact, #about").removeClass("toggled");
$("#home, #contact, #about").removeClass("toggled_alt");
});
我現在想做的是,當向下/向上滾動滾輪時,我希望頁面滾動到下一個div。 我一直在搜索google一段時間,出現的所有內容都是關於平滑滾動的,這不是我想要的。 任何幫助將是巨大的,謝謝。
查看此答案及其注釋以及wheel event的MDN頁面 。
看起來您可以像這樣綁定到事件:
$(window).on('wheel', function(event){
但這可能是壓倒性的,因為它是鼠標滾輪的每次“單擊”。
看到這個小提琴 。 僅在Chrome中測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.