简体   繁体   English

用宽松的jQuery滚动

[英]Scroll with easing jQuery

I'm trying to animate one sigle-paged-website and when I click on the menu it scrolls to that section, I added a simple animation with a constant speed but I want something like this when you click on the menu >>> http://www.sergioarantes.com/ 我正在尝试为一个单页页面网站制作动画,当我单击菜单上的它滚动到该部分时,我以恒定的速度添加了一个简单的动画,但是当您单击菜单上的>>> http时,我想要这样的动画://www.sergioarantes.com/
I found that easing jquery could help and here is my js code "it's not working" 我发现放宽jquery可能会有所帮助,这是我的js代码“不起作用”

$(document).ready(function(){

$("#first-showup header nav .nav-bar #menu-items ul li a").click(function(){

var $block = $(this).data("block");

var $thisBlock = $("#"+$block);


  $("html, body").animate({
    "scrollTop": $thisBlock.position().top }, 
          {
              duration: 1200,
              easing: "easeInOutExpo"
          });
  });

On their website on this animation they say to use this model: 他们在网站上以动画形式表示使用此模型:

div.animate({ top: '-=100px' }, 600, 'easeInQuart', function () { … })

But I can't modify it on my code thank you 但是我不能在我的代码上修改它,谢谢

Richard. 理查德

This should work for you 这应该为你工作

$(document).ready(function(){

      $("#first-showup header nav .nav-bar #menu-items ul li a").click(function(){

        var $block = $(this).data("block");

        var $thisBlock = $("#"+$block);

             $('html, body').animate({
              scrollTop: $thisBlock.offset().top
            }, 1000);

      });
    });

the jQuery method $(selector).animate(); jQuery方法$(selector).animate(); requires as first parameter a Object containing some CSS properties camelCase written. 需要第一个参数为一个Object其中包含编写的一些CSS属性camelCase。 The property scrollTop is not a CSS property. 属性scrollTop不是CSS属性。 In any case you can solve the problem in some ways, like: 无论如何,您都可以通过某些方式解决问题,例如:

  • Create a Javascript/jQuery function that sets scrollTop property on the document, you can do it basically with a simple window.setInterval(); 创建一个在文档上设置scrollTop属性的Javascript / jQuery函数,基本上可以使用一个简单的window.setInterval();
  • Use a CSS Trick (look Scroll Based Animations jQuery CSS3 ) to make scrolling effect on the page and animate it. 使用CSS技巧(请参见基于滚动的动画jQuery CSS3 )在页面上产生滚动效果并对其进行动画处理。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM