页面加载后如何使用 jQuery 滑动

发布于 2024-08-29 05:03:13 字数 298 浏览 3 评论 0原文

我在尝试向下滑动更多信息 div 时遇到计时问题。我想要的功能是,一旦页面已经呈现,div就会从顶部滑落。我的问题是,如果我使用 $(document).ready().. 动画不会明显发生。

这是我的代码:

    $(document).ready(function() {
        $(".MoreInfo").slideDown('slow');
    });

例如,如果我将它绑定到其他一些元素的点击上,它就会工作得很漂亮。但我不知道如何让它在页面加载后明显地向下滑动。 谢谢!

I am having a timing issue when attempting to slide down my more info div. My desired functionality is that the div slidesdown from the top once the page has already been rendered. My problem is if I use $(document).ready().. the animation does not visibly occur.

Here is my code:

    $(document).ready(function() {
        $(".MoreInfo").slideDown('slow');
    });

If I strap it to some other element's click for example, it works beautifully. But I am not sure how to make it visibly slide down once the page has loaded.
Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残花月 2024-09-05 05:03:13

进行混合和匹配,

$(window).load(function()  

我尝试使用: and

$(document).ready(function()  

但没有任何运气。我最终使用了

 $(document).ready(function() {
    $(".MoreInfo").slideUp(1).delay(2000).slideDown('slow');

,这似乎有效。我认为这与已经显示的元素有关。

I tried mixing and matching using:

$(window).load(function()  

and

$(document).ready(function()  

but did not have any luck. I ended up using

 $(document).ready(function() {
    $(".MoreInfo").slideUp(1).delay(2000).slideDown('slow');

and that seemd to work. I think it had to do with the element already being displayed more than anything else.

两个我 2024-09-05 05:03:13

您可能想尝试使用

$(window).load(function() 

而不是

$(document).ready(function() 

因为当 $(document).ready 触发时您尝试操作的某些元素可能未完全加载。

You might want to try using

$(window).load(function() 

instead of

$(document).ready(function() 

as some of the elements you are trying to manipulate might not be completely loaded when $(document).ready fires.

朱染 2024-09-05 05:03:13

也许可以尝试使用 body onload 来代替

$("body").load(function() {
    $(".MoreInfo").slideDown('slow');
});

...只要 DOM 可以操作,document.ready 就会发生,不一定一旦页面显示 - 它可能在页面显示之前发生。您也可以尝试将其放在 setTimeout 调用中以留出一点额外的时间

Perhaps try body onload instead

$("body").load(function() {
    $(".MoreInfo").slideDown('slow');
});

...document.ready occurs as soon as the DOM can be manipulated, not necessarily once the page is displayed - it could be well before the page is displayed. You could also try putting this on a setTimeout call to allow a little extra time

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文