gpt4 book ai didi

javascript - 图像相互叠加的动画

转载 作者:行者123 更新时间:2023-11-28 16:58:15 33 4
gpt4 key购买 nike

我正在尝试实现一个小的图像动画,以半透明的方式将图像叠加在一起,以便可以同时看到所有图像。

此外,按钮应该可以打开和关闭,这样可以实现不同的图像或颜色组合。

目前我只能使用每个按钮一次,而且只能看到 2 张图片。

( Code Pen )

function crossfadeImages() {
var $active = $('#show-img .active');
var $next = $('#show-img .next');

$active.animate({
opacity: "0.5"
}, 500, function() {
$(this).stop('style');
});
}

$('.buttons a.page').first().addClass('activeButton');

$('.buttons a.page').click(function() {
$('.buttons a.page').removeClass('activeButton');
$(this).addClass('activeButton');
if (!$('#show-img').find('img').eq($(this).attr('rel')).hasClass('active')) { //if the clicked image is not already the active image

$('#show-img').find('img').eq($(this).attr('rel')).addClass('next'); //flag the image as the next one
crossfadeImages();
}
return false;
})
img {
width: 65%;
opacity: 1;
}
/*image show*/

#show-img {
position: relative;
}
#show-img img {
position: absolute;
z-index: 1;
background-color: #fff;
}
#show-img img.active {
z-index: 3
}
#show-img img.next {
z-index: 2
}
img {
display: block;
}
.button {
width: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">

<div class="large-5 columns buttons">
<br>
<br>
<br>
<br>
<h4>the possebilities</h4>
<br>
<br>
<br>
<br>
<a class="page activeButton radius blue button" href="#" rel="0">button1</a>
<br>
<a class="page radius green button" href="#" rel="1">button2</a>
<br>
<a class="page radius red button" href="#" rel="2">button3</a>
<br>
<a class="page radius black button" href="#" rel="3">button4</a>

</div>

<div id="show-img" class="large-7 columns show-img">
<h1>main header</h1>
<img class="active" src="http://vollwebdesign.com/foundation- testing/blue.png">
<img src="http://vollwebdesign.com/foundation-testing/rosa.png">
<img src="http://vollwebdesign.com/foundation-testing/yellow.png">
<img src="http://vollwebdesign.com/foundation-testing/orange.png">

</div>
</div>

最佳答案

我稍微调整了你的代码并制作了这个 fiddle 。 https://jsfiddle.net/osha90/g3Lwst0n/ .希望这就是您要找的东西

    <div class="row">

<div class="large-5 columns buttons">
<br> <br> <br> <br>
<h4>the possebilities</h4> <br> <br> <br> <br>
<a class="page activeButton radius blue button" href="#" rel="0">button1</a><br>
<a class="page radius green button" href="#" rel="1">button2</a><br>
<a class="page radius red button" href="#" rel="2">button3</a><br>
<a class="page radius black button" href="#" rel="3">button4</a>
</div>

<div id="show-img" class="large-7 columns show-img">
<h1>main header</h1>
<img src="http://vollwebdesign.com/foundation-testing/blue.png">
<img src="http://vollwebdesign.com/foundation-testing/rosa.png">
<img src="http://vollwebdesign.com/foundation-testing/yellow.png">
<img src="http://vollwebdesign.com/foundation-testing/orange.png">

</div>
</div>

CSS代码

/*image show*/
#show-img {
position: relative;
}
#show-img img {
position: absolute;
z-index: 1;
background-color: transparent;
width: 65%;
opacity: 0;
transition: all 0.5s ease-out;
}
#show-img img:first-of-type {
opacity: 1;
}
#show-img img.active{
opacity: 0.7;
}
.button {
width: 200px;
}

JS代码

$('.buttons a.page').click(function() {
if($("#show-img img:eq(0)").css("opacity") == 1){
$("#show-img img:eq(0)").css("opacity","0.7");
}
var index = $(this).attr("rel");
var correspondingImage = $("#show-img img:eq(" + index + ")");
if ($(this).hasClass("active")) {
$(this).removeClass("active");
correspondingImage.removeClass("active");
} else {
$(this).addClass("active")
correspondingImage.addClass("active");
}
return false;
})

关于javascript - 图像相互叠加的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31730030/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com