在幻灯片中的图片上添加渐变淡出效果

4
我正在尝试在幻灯片中的图像上添加渐变效果,这样,在查看某个图片时(我的幻灯片显示3张图片,一张居中,另外两张分别是前一张和后一张的一小部分),两侧的图片将有这种渐变效果,左边的前一张图片将其左侧淡出,反之亦然。你懂我的意思吗?与此类似的是在这里评论过的:如何在CSS中对图像应用渐变叠加层?我有两个.png文件,一个向左渐变,一个向右渐变。在HTML和CSS方面该如何应用?你会在.css的底部看到它们,但是它们没有被正确应用,而且在HTML中也没有相应的
标签(需要吗?)。当你悬停在下一张和上一张图片上时,它们也应该稍微变亮一些(失去一些渐变效果)。例如:http://www.deadmau5.com HTML
<div class="hero">
    <div class="hero-carousel">

        <article>
          <img src="images/deadmau5/slide1.jpg" />
        </article>

        <article>
          <img src="images/deadmau5/slide2.jpg" />
        </article>

        <article>
          <img src="images/deadmau5/slide3.jpg" />
        </article>

        <article>
          <img src="images/deadmau5/slide4.jpg" />
        </article>

    </div>
</div>

javascript

<script>
    $(document).ready(function(){
        $('.hero-carousel').heroCarousel({
            easing: 'easeOutExpo',
            css3pieFix: true
        });
    });
</script>

CSS

.hero {
    width: 1366px;
    height: 340px; position:absolute;top:270px;
    overflow: hidden;
    margin-bottom: 48px;
    margin: 0 auto;
    border-top:9px solid rgba(51, 51, 51, .15);
    border-bottom: 9px solid rgba(51, 51, 51, .15);
    padding: 0 0 12px 0;
}

.hero-carousel article {
    width: 970px;
    margin: 0 auto;
    height: 470px;
    display: block;
    float: left;
    position: relative;
}

.hero-carousel-container article {
    float: left;
}

.hero-carousel article img{
    border-style:solid;border-width:6px;color:#000; position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.hero-carousel article .contents {
    position: relative;
    z-index: 2;
    top: 72px;
    left: 48px;
    list-style: none;
    color: #000;
    width: 556px;
    padding: 20px;

    background: rgba(255,255,255,0.8);
    -pie-background: rgba(255,255,255,0.8);

    -moz-border-radius: 20px;
    -webkit-border-radius: 20px;
    border-radius: 20px;

    behavior: url(/assets/PIE.htc);
}

.hero-carousel-nav {
    width: 980px;
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-left: -490px;
    z-index: 2;
}

.hero-carousel-nav li {
   position: absolute;
   bottom: 48px;
   right: 48px;
   list-style: none;
}

.hero-carousel-nav li.prev {
    left: -50px;
    right: auto;
    bottom: 100px;
}
.hero-carousel-nav li.next {
    right: -30px;
    left: auto;
    bottom: 100px;
}

.hero-carousel-nav li a {     
    background: none repeat scroll 0 0 #D21034; 
    color: #FFFFFF;
    display: block;
    float: left;
}

.hero-carousel-nav li.next a { 
    background: url('../images/deadmau5/large-arrow-right.png'),
                -5px -7px no-repeat;
    display: inline-block;
    width: 105px;        /*width of your img*/
    height: 105px;      /*height of your img*/
    font-size: 0px; 
    right: -15px;  /*this is better than 1px*/
    bottom: 100px;
    overflow:hidden;
    outline:none;
}

.hero-carousel-nav li.prev a { 
    background: url('../images/deadmau5/large-arrow-left.png'),
                -7px -7px no-repeat;
    display: inline-block;
    width: 105px;        /*width of your img*/
    height: 105px;      /*height of your img*/
    font-size: 0px;    /*this is better than 1px*/
    left: -50px;
    bottom: 100px;
    overflow:hidden;
    outline:none;
}

如果您查看样式表,大约在第250行左右就是您想要的内容。他们使用了positionz-index来覆盖淡入淡出元素,并在悬停时将opacity设置为小于1的小数。 - Ally
我经验不是很丰富,你能否发一些“代码”来说明吗?请保持非常简单,因为同样的原因,哈哈。 - Bad Habit
就像我一样,我也试图复制箭头在悬停时“发光”的效果,但没有成功。 - Bad Habit
1个回答

1

有几种处理方法,但这是一个简单的示例,说明了该网站如何布局所有内容。

CSS

#container {
    position: relative;
    width: 504px;
    margin: 0 auto;
}

#slide-container {
    width: auto;
}

.article {
    display: inline-block;
}

.article img {
    width: 165px;
    height: auto;    
}

#overlay-left {
    position: absolute;
    width: 165px;
    height: 60px;
    top: 0;
    left: 0;
    background: url('http://www.deadmau5.com/wp-content/themes/deadmau5/images/slider-fade-left.png') no-repeat top left;
    z-index: 2;
}

#overlay-right {
    position: absolute;
    width: 165px;
    height: 60px;
    top: 0;
    right: 0;
    background: url('http://www.deadmau5.com/wp-content/themes/deadmau5/images/slider-fade-right.png') no-repeat top right;
    z-index: 2;
}

#overlay-left:hover, #overlay-right:hover {
    opacity: 0.8;
}
​

HTML

<div id="container">
    <div id="slide-container">
        <div class="article">
            <a href="">
                <img src="http://www.deadmau5.com/wp-content/uploads/2012/06/slide1.jpg" />
            </a>
        </div>
        <div class="article">
            <a href="">
                <img src="http://www.deadmau5.com/wp-content/uploads/2012/06/slide1.jpg" />
            </a>
        </div>
        <div class="article">
            <a href="">
                <img src="http://www.deadmau5.com/wp-content/uploads/2012/06/slide1.jpg" />
            </a>
        </div>
    </div>
    <div id="overlay-left"></div>
    <div id="overlay-right"></div>
</div>

这里有一个 JSFiddle,如果你想玩一下的话。


是的,但是我该如何在我的项目中实现这个呢?由于我使用的东西不同,我应该用什么来替换#overlay呢?我的叫做.heroCarousel或者其他什么名字。 - Bad Habit
在这种情况下,“container”将变成“hero”,而“slide-container”将变成“hero-carousel”。您需要在“hero-carousel”之后添加“overlay-left”和“overlay-right”元素。 - Ally
等等,我真的很困惑。我不是很擅长这个,也不确定在问题中应该在我的已有的 .css 中添加什么。 - Bad Habit
你需要添加CSS和HTML代码。请比较我的基本示例代码并调整你的代码。在这个场所里,完整解决方案的编写超出了讨论范围,因为那就是我替你完成工作。 - Ally
我所做的就是将导航的z-index设置为3,并在左右覆盖层中添加一个新的opacity:x.x;(当未被悬停时)。 - Bad Habit
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接