单双击回顶部(移动端)

移动端双击回到顶部:

   var touchtime = new Date().getTime();

   $(".header").on("click", function() {

      if(new Date().getTime() - touchtime < 500) {

        console.log("dblclick");

        $('html , body').animate({

           scrollTop: 0

        }, 'slow');

      } else {

        touchtime = new Date().getTime();

        console.log("click")

      }

   });

单击回到顶部:

    $(window).scroll(function(){

        if($(this).scrollTop() > 100){

            $('.top').fadeIn();

        }else{

            $('.top').fadeOut();

        }

    });

   $(".top").click(function(){

      $('html , body').animate({

        scrollTop: 0

      }, 'slow');

   })

posted @ 2019-06-10 12:03  de玻璃  阅读(212)  评论(0编辑  收藏  举报