如何使用velocity.js中的complete属性来触发localscroll(How to use the complete property in velocity.js to trigger

编程入门 行业动态 更新时间:2024-10-27 17:19:06
如何使用velocity.js中的complete属性来触发localscroll(How to use the complete property in velocity.js to trigger localscroll)

我正在使用velocityjs , localscroll (需要scrollTo )。

我有一个默认隐藏的表单。 我正在使用一个锚标签,点击后会显示表格。

HTML

<a href="#myForm" class="button" id="show">Show the form</a>

jQuery的

$('#show').click(function (event) { $('#myForm') .velocity('slideDown', {'duration': 2000}) .velocity({'opacity': 1}, { 'complete': function () { $('#myForm').localScroll({ 'target': 'body', 'duration': 2000, 'easing': 'swing', 'hash': false }); } }); });

我遇到的是因为我没有event.preventDefault来停止跳转到目标的默认浏览器操作,我的页面正在逐渐淡入我的表单。

表格完全显示 ,我想滚动页面。

如果我使用event.preventDefault() ,页面将根本不滚动。 这是有道理的,因为那时我告诉它不要做任何事情。

I am using velocityjs, localscroll (which needs scrollTo).

I have a form that is hidden by default. I am using an anchor tag that when clicked, will show the form.

html

<a href="#myForm" class="button" id="show">Show the form</a>

jquery

$('#show').click(function (event) { $('#myForm') .velocity('slideDown', {'duration': 2000}) .velocity({'opacity': 1}, { 'complete': function () { $('#myForm').localScroll({ 'target': 'body', 'duration': 2000, 'easing': 'swing', 'hash': false }); } }); });

What I'm running into is that because I don't have an event.preventDefault to stop the default browser action of jumping to the target, my page is jumping to my form as it is fading in.

I'd like to scroll the page after the form is fully shown.

If I use event.preventDefault(), the page will not scroll at all. Which makes sense since at that point I am telling it not to do anything.

最满意答案

不要将它与另一个库复杂化,只需使用Velocity的scroll命令滚动到所需位置,例如:

//... complete: function (form) { $(form).velocity('scroll', { duration: 2000, easing: "swing" }); }

Instead of complicating it with yet another library, just use Velocity's scroll command to scroll to the required position, for example:

//... complete: function (form) { $(form).velocity('scroll', { duration: 2000, easing: "swing" }); }

更多推荐

本文发布于:2023-07-31 22:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1348975.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   属性   js   complete   velocity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!