jQuery 循环同时淡入淡出

发布于 2024-10-16 16:58:52 字数 656 浏览 1 评论 0原文

我在使用 jQuery Cycle Lite 插件 (http://jquery.malsup.com/cycle/) 时遇到问题。

图像似乎在淡入之前完全淡出,我希望它们同时淡入/淡出。 http://hardingandwhitlock.com/v6/content/background

我将同步选项设置为 1

$.fn.cycle.defaults = {
     timeout:       2000, 
     speed:         200, 
     next:          null, 
     prev:          null, 
     before:        null, 
     after:         null, 
     height:       'auto',
     sync:          1,    
     fit:           0,    
     pause:         0,    
     delay:         0,    
     slideExpr:     null  
};

非常感谢任何帮助!

I am having an issue with the jQuery Cycle Lite Plugin (http://jquery.malsup.com/cycle/)

The images seem to be fading out completely before fading in, and I want them to fade in/out simultaneously. http://hardingandwhitlock.com/v6/content/background

I have the sync option set to 1

$.fn.cycle.defaults = {
     timeout:       2000, 
     speed:         200, 
     next:          null, 
     prev:          null, 
     before:        null, 
     after:         null, 
     height:       'auto',
     sync:          1,    
     fit:           0,    
     pause:         0,    
     delay:         0,    
     slideExpr:     null  
};

any help is much appreciated!

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

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

发布评论

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

评论(2

梦言归人 2024-10-23 16:58:52

听起来您正在尝试从一张图像到另一张图像进行淡入淡出过渡。为此,您需要使用两个图像:

<img id="backImg" />
<img id="frontImg" />

#backImg 设置为 #frontImg 后面,如下所示:

#backImg
{
    position: absolute;
}

然后淡出正面图像...这将自动执行您的交叉淡入淡出效果,因为背面图像已加载在其后面。淡入淡出完成后,将前图像的源设置为后图像的 src,显示它,并将下一个图像预加载到后图像中:

function transitionImages(preloadImgUrl)
{
    $("#frontImg").fadeOut("slow", function()
    {
        $("#frontImg").attr("src", $("#backImg").attr("src")).show();
        $("#backImg").attr("src", preloadImgUrl);
    }
}

这一切都假设您的图像大小相同。如果没有,您需要对 css 进行更精细的处理,并将图像包装在淡出的 div 中。

It sounds like you are trying to do a cross-fade transition from one image to another. To do this, you'll want to use two images:

<img id="backImg" />
<img id="frontImg" />

Set #backImg to be behind #frontImg like so:

#backImg
{
    position: absolute;
}

Then fadeOut the front image... this will automatically do your crossfade effect because the back image is already loaded behind it. When the fade is done, set the source of the front image to the back image's src, show it, and pre-load the next image into the back image:

function transitionImages(preloadImgUrl)
{
    $("#frontImg").fadeOut("slow", function()
    {
        $("#frontImg").attr("src", $("#backImg").attr("src")).show();
        $("#backImg").attr("src", preloadImgUrl);
    }
}

This all assumes your images are identically sized. If not, you'll want to be just a little more elaborate with the css and wrap the images in divs that fade out.

赠意 2024-10-23 16:58:52

这最终是由于在 标记之间插入了一些
造成的,并且脚本也在所有标记之间淡入/淡出这些内容。图像

该网站是在 Drupal 中完成的,因此图像应该插入正文中,而

<div id="slideshow"><img src="" /><img src="" />...</div>

不是在单独的行中,

<div id="slideshow">
   <img src="" />
   <img src="" />
</div>

Drupal 似乎在每个单独的行之间插入
。不确定其他 CMS 是否也会这样做

This ended up being caused by some <br> being inserted between the <img> tags, and the script was fading those in/out as well in between all the images

The site is being done in Drupal, so the images should be inserted into the body as

<div id="slideshow"><img src="" /><img src="" />...</div>

instead of on separate lines

<div id="slideshow">
   <img src="" />
   <img src="" />
</div>

Drupal seems to insert <br>between each separate line. Not sure if other CMS will do the same

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