jQuery 1.6.3 显示和隐藏之间的动画差异

发布于 2024-12-05 04:06:41 字数 469 浏览 1 评论 0原文

我有多个带有链接的容器,如下所示:

<div class="items" id="first"><a href="item1">item 1</a></div>

容器有背景图像,链接隐藏为: display: none;

$(".items").mouseover(function() {
    $("a", this).show(1500);
}).mouseout(function() {
    $("a", this).hide(1500);
});

实例

现在的问题是文本显示缓慢,但所占据的位置立即被占据。如何实现相反的效果——文本立即可见,而其占据的位置缓慢显示?

I have multiple containers with links, like this:

<div class="items" id="first"><a href="item1">item 1</a></div>

The containers have a background image and the links are hidden with: display: none;

$(".items").mouseover(function() {
    $("a", this).show(1500);
}).mouseout(function() {
    $("a", this).hide(1500);
});

Live example

Now the problem is that the text is showing slow, but the place which occupies is taken immedeiatly. How to achieve the oposite - the text to be visible immediately and its place which it occupies to be shown slowly?

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

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

发布评论

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

评论(3

握住我的手 2024-12-12 04:06:41

http://jsfiddle.net/wtZPQ/2/

您可能还需要显示:阻止以确保文本不换行。

http://jsfiddle.net/wtZPQ/2/

you may also want to display:block to makesure the text doesnt wrap.

看春风乍起 2024-12-12 04:06:41

当您的 隐藏时,它们不会占用屏幕上的空间。一旦它们不再隐藏,它们就会突然占据空间。这就是为什么在您的实例中,将鼠标悬停时您会立即看到该空间打开。

文本已从占据零空间变为占据全部空间。它不会立即可见,因为不透明度从零开始,仅在 1500 毫秒后达到完全不透明度。但即使不透明度为零,它现在仍然存在,占据空间。

所以你问的实际上是不可能的。您可以使您的 绝对定位,这样它们就不会占用空间,然后在它们完全淡入后使图形之间的空间扩大,但我不确定这就是您想要的去....

When your <a> are hidden, they take up no space on the screen. As soon as they become un-hidden, they suddenly take up space. That is why, in your live example, on hover you immediately see that space open up.

The text has gone from taking up zero space to taking up it's full space. It's not immediately visible because the opacity starts at zero, and only reaches full opacity after 1500 milliseconds. Even at opacity zero, though, it still now exists, taking up space.

So what you're asking isn't really possible. You COULD make your <a> absolutely positioned, so they never take up space, then after they fade in completely make the space between your graphics expand, but I'm not sure that's what you're going for....

我早已燃尽 2024-12-12 04:06:41

哦,奇怪的是,我在 JQuery 1.4.4 中尝试过,它工作正常,但如 jsfiddle 所示,它在 1.6.3 中中断。

无论如何,我猜测这是因为 a 标签默认具有 inlinedisplay 样式,它不允许您分配宽度。

您可以强制它为 .items a { display:inline-block; } 然后使用 JQuery 隐藏它们:

$(".items a").hide();

http://jsfiddle.net/wtZPQ/3/

Oh weird, I tried it in JQuery 1.4.4 and it works correctly, but as shown in your jsfiddle it breaks in 1.6.3.

Anyway, i guessed that it was because an a tag default has a display style of inline which doesn't let you assign width.

You can force it to be .items a { display:inline-block; } and then hide them using JQuery:

$(".items a").hide();

http://jsfiddle.net/wtZPQ/3/

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