Velocity Scroll Issue with Version 2.0.1

倖福魔咒の 提交于 2019-12-21 21:26:07

问题


An update to the newest version of Velocity (2.0.1) causes an issue related to scroll. Specifically, the following error message is thrown:

Error: Velocity: First argument (scroll) was not a property map, a known action, or a registered redirect. Aborting.

The following example works fine with Velocity 1.5: https://codepen.io/julianshapiro/pen/kBuEi

Since SO requires code, here is the relevant portion from the CodePen:

$("#element3").velocity("scroll", { 
  container: $("#container"),
  duration: 800,
  delay: 500
});

However, when Velocity 2.0.1 is used instead, it throws the error: https://codepen.io/anon/pen/QQgOPx

Can someone tell me how to fix this?


回答1:


It appears that scroll action is available in v1.5.0 (Line: 3161) but appears to be missing from v2.0




回答2:


Coder of Velocity V2 here, and going to point at the V2 Changes file:

Currently disabled / not updated:

  • Scroll (working, but not happy with interface - it's a property if people want to play, alias of scrollTop, there's also scrollLeft)

So it's in, but I'm likely to change the underlying code (the interface will remain identical if/when that happens though), it is however a normal property to animate now (and will stay as such) - so to use it now you'd do something like:

$("#container").velocity({scrollTop: "500px"}, {
  duration: 800,
  delay: 500
});

If you want to scroll down to another element, then you'd need to find the relative position of that element compared to the first (which should be a separate issue, but I will add to the wiki when it's done).

Note: I'd encourage people to use "scrollTop" instead of "scroll" to make it obvious that you're not using "scrollLeft".

Note2: "scrollTop" is in 2.0.1, the other ones will be in the next beta 2.0.2 - but are in the repo right now.



来源:https://stackoverflow.com/questions/48757902/velocity-scroll-issue-with-version-2-0-1

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