简体   繁体   English

Javascript / CSS幻灯片:使用透明胶片突出了我不知道如何解决的缺陷

[英]Javascript/CSS slideshow: Using transparencies highlights flaws I don't know how to fix

As much as I'd love to have this be as broad as possible to help future coders, this is a rather specific problem. 我很想尽可能广泛地帮助将来的编码人员,这是一个相当具体的问题。

As you can see in this jsfiddle , this slideshow seems to have an issue with pictures with transparencies. 正如您在jsfiddle中所看到的,此幻灯片似乎对带有透明胶片的图片有问题。 With transparencies, there is a fairly jarring transition. 有了透明胶片,转换就会变得很麻烦。 If possible, I'd like to have the old picture fade out as the new picture is fading in. 如果可能的话,我希望随着新图片的淡入而使旧图片淡出。

And a note: the slideshadow div is there for a reason, mainly for box-shadow uses with greater control over z-index. 还有一个注意事项:slideshadow div的存在是有原因的,主要用于框阴影的使用,可以更好地控制z-index。

HTML: HTML:

<div id="slideshow">
   <img class="active" src="http://i.imgur.com/tqMy9wn.png" alt="" />
   <img src="http://i.imgur.com/vNyEFB0.png" alt="" />
   <div id="slideshadow">&nbsp;</div>
</div>

CSS: CSS:

#slideshow {
    position:relative;
    float:left;
    height:245px;
    width:200px;
}

#slideshow IMG {
    position:absolute;
    top:0;
    left:0;
    z-index:8;
    opacity:0.0;
}

#slideshow IMG.active {
    z-index:10;
    opacity:1.0;
}

#slideshow IMG.last-active {
    z-index:9;
}

#slideshadow {
    position:absolute;
    height:245px;
    width:200px;
    box-shadow:inset 0px 0px 80px 0px rgba(0,0,0,0.75);
    z-index:15;
}

JS: JS:

  function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ($active.length == 0) $active = $('#slideshow IMG:last');

    var $next = $active.next('img').length ? $active.next('img') : $('#slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({
        opacity: 0.0
    })
        .addClass('active')
        .animate({
        opacity: 1.0
    }, 2000, function () {
        $active.removeClass('active last-active');
    });
}

$(function () {
    setInterval(slideSwitch, 7000);
});

Adding an explicit fade to transparent seems to work: 向透明添加显式淡入似乎可行:

$active.animate({
    opacity: 0.0
}, 2000);

http://jsfiddle.net/tbyccesq/ http://jsfiddle.net/tbyccesq/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我不知道如何修复 javascript func 中的这个错误 - I don't know how to fix up this bug in javascript func 我有一个JavaScript范围错误,我不知道如何解决此问题 - I have a javascript scope error, I don't know how to fix this 我不知道如何解决我的反向数组/字符串 - I don't know how to fix my reverse array/string 我不知道如何解决事件问题? - I don't know how to fix problem with events? 使用Jquery创建游戏,涉及对象“删除”另一个我不知道如何解决的巨大问题 - Creating a game using Jquery, huge issue involving an object 'removing' another that I don't know how to fix 我不知道如何解决成绩计算器功能 - I don't know how to fix my grade calculator function 我的Javascript不起作用。不知道它是函数,我是如何调用它,我使用的CSS或者是什么 - My Javascript doesn't work. Don't know if it's the Function, how I'm calling it, the CSS I used or what 我知道为什么我会收到意外的 { 令牌,但当我的 php 需要将数据集合发送到 javascript 时,我不知道如何修复它 - I know why I am getting unexpected { token but I don't know how to fix it when my php needs to send collection of datas to javascript javascript 我不知道如何使用 getItem 获取特定对象 - javascript I don't know how to get a specific object with getItem 如何使用CSS Grid和Javascript制作幻灯片 - How to make a slideshow using CSS Grid and Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM