gpt4 book ai didi

javascript - 如何让 div 框淡入和淡出 div

转载 作者:行者123 更新时间:2023-11-28 07:31:02 24 4
gpt4 key购买 nike

我目前正在开发一个使用复选框来显示图像和删除图像的页面。我有添加图像和删除图像部分工作。我只是无法让图像淡入和淡出 div。谁能帮忙?

<html><head>
<style>
.overlay {
display: none;
position: absolute;

}
.right {
position: absolute;
right: 0px;
width: 300px;
border:3px solid #8AC007;
padding: 10px;
}
#map {
position: relative;
right: -780px;
width: 200px;
height: 200px;
display: none;
background: url(tn_bandannatop.png) 0 0;
}
#station_A { top: 5px; left: 85px }
#station_B { top: 150px; left: 180px }
.hover { color: green }
</style>
<div id="map" >
<span id="station_A" class="overlay"><img src="/tn_WhiskersPrinceworkup.png"></span>
<span id="station_B" class="overlay">Highlight image here.</span>

</div>

<p>
<h2>Choose a Shirt</h2>
<form>
<input type="checkbox" name="image" value="station_A">Station Alfa<br>
<input type="checkbox" name="image" value="station_B">Station Beta
<input type="checkbox" name="image" value="bandanna" id="checkbox1">Bandanna
</form>
</p>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$("input[type='checkbox']").change(function() {
var state = $(this).val();
//
$("#"+state).toggleClass("overlay");
});
$(document).ready(function(){
$('#checkbox1').change(function(){
if(this.checked)
$('#map').fadeIn('slow');
else
$('#map').fadeOut('slow');

});
});
</script>
</body></html>

Fiddle 在这里

更新:更新 fiddle 在这里添加图像 url。此外,div 贴图应该淡入淡出,但由于某种原因它在 fiddle 中不起作用。在我的开发箱上运行良好。

最佳答案

请试试这个。

$(document).ready(function () {
$("input[type='checkbox']").change(function () {
var state = $(this).val();
$("#" + state).toggleClass("overlay");
});
$('#checkbox1').change(function () {
if (this.checked) $('#map').fadeIn('slow');
else $('#map').fadeOut('slow');

});
});

DEMO

关于javascript - 如何让 div 框淡入和淡出 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508402/

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