问题
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