经常不记得代码,在这里总截下,方便以后查看:

方法1:使用锚点 (不多说百度下 比较多)

方法2:jQuery实现

$(document).ready(function (){  
            $("#scroll2").click(function (){      //无过渡效果
                $('html, body').scrollTop(offset ); 
            });

            $("#scroll2").click(function (){     //平滑滚动到指定位置
                $('html, body').animate({  
                    scrollTop: offset        //offset,数值你要到滚动的位置 
                }, 2000);  
            });  
        });  

    Js 实现

用 requstAnimationFrame(function) 回调可以实现平滑滚动,无需使用计时器

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案