预加载多个图像,然后使用 jquery 让它们淡入视图

发布于 2024-10-06 22:35:55 字数 1012 浏览 2 评论 0原文

作为参考,我需要帮助的内容位于:

http://www.photographeller.com/portfolio

我想做的是,当您单击要打开的投资组合部分时,在打开之前预加载图像,然后展开该部分并使图像淡入视图,在图像加载时可能会显示加载程序图像或某种效果。而不是现在的样子,该部分打开并且图像突然加载。然后,当单击该部分关闭时,使图像淡出。另外,如果可能的话,在该部分扩展时对其进行一些缓和,但这只是我的挑剔。

我现有的 jquery 代码会切换更改图像容器宽度的类。应用的类还将主图像的显示更改为无,并将该部分中其他图像的显示从无更改为内联。还有另一段代码,正如我在关于堆栈溢出的上一个问题中提供的那样,它获取单击部分中所有图像的组合宽度并应用于它包含的 div。这是我实现此效果的代码:

<script type="text/javascript">

$(document).ready(function(){       
$(".boxgrid").click(function () {
$(this).toggleClass("openBoxgrid", 1000);

});

$('div.innerOpen').each(function() {
    var totalImageWidth = 0;

    $("img", this).each(function () {
      totalImageWidth += $(this).width();
    });

    $(this).width(totalImageWidth);
});

});

</script> 

我在 .boxgrid 的 .click 函数中尝试了一些操作,例如对所有具有隐藏类的图像进行 .fadeIn() ,但它并没有真正按照我的方式工作想要。它还会导致显示该类别的每个部分中的所有图像,而不仅仅是单击的部分。

好吧,我为这个冗长的问题道歉。对此的任何帮助将不胜感激。谢谢你!

For reference, the thing I need help with is located at:

http://www.photographeller.com/portfolio

What I'd like to do is when you click a portfolio section to open, before it opens have the images preload, then have the section expand and have the images fade into view, with maybe a loader image while the images are loading or something of that effect. Instead of how it is now, where the section opens and the images load abruptly. Then when the section is clicked closed, have the images fade out. Also if it's possible, have some easing on the section when it expands, but that's just me being nit picky.

The jquery code I have in place toggles the class that changes the width of the container of the images. The class applied also changes the display of the main image to none, and changes the display of the other images in the section from none to inline. And another bit of code, as supplied to me in my last question on stack overflow, that takes the combined width of all the images in the section clicked and applies to it's containing div. Here is the code I have for this effect:

<script type="text/javascript">

$(document).ready(function(){       
$(".boxgrid").click(function () {
$(this).toggleClass("openBoxgrid", 1000);

});

$('div.innerOpen').each(function() {
    var totalImageWidth = 0;

    $("img", this).each(function () {
      totalImageWidth += $(this).width();
    });

    $(this).width(totalImageWidth);
});

});

</script> 

I've tried a few things in the .click function for .boxgrid, like .fadeIn() on all images with the class of hidden, but it doesn't really work the way I'd like. And it also causes ALL images in every section with that class to appear, and not just the section that is clicked on.

Well, I apologize for the lengthy question. Any help on this would be greatly appreciated. Thank you!

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

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

发布评论

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

评论(1

说好的呢 2024-10-13 22:35:55

当前的问题是您在淡入图像之前更改宽度。

这开始执行,但需要一秒钟,

$(this).toggleClass("openBoxgrid", 1000);

平均而言,当您更改宽度时,这是瞬时的。也许更好的效果是先使用第一个图像大小的 div,然后再使用内部所有图像大小的 div。

然后将第一个动画调整为另一个动画的大小,这将产生窒息效果。

The current problem is that you change the width before you fade in the images.

This starts to execute but it takes one second

$(this).toggleClass("openBoxgrid", 1000);

Mean while you change the width and that's instantaneous. Probably a better effect will be to have a div of the size of the first image, then a div the size of al the images inside.

Then animate to the with of the first to the size of the other, it will a smother effect.

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