[英]How to make a overlay fit in another image
我目前有一個工作系統,您可以在其中選中覆蓋圖像的復選框,但是,我遇到的問題是圖像已放置在計算機屏幕內部,因此不是很靠邊。 可以有人幫忙嗎?
<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: 452px;
height: 344px;
background: url(BLANK-COMPUTER-SCREEN.png);
}
#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 style="background:url(/BLANK-COMPUTER-SCREEN.PNG)" 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>
$(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');
});
});
</script>
小提琴在這里。
您需要將position:absolute
設置為#station_A
和#station_b
而不是.overlay
,因為您使用.overlay
在jQuery中進行切換,因此將失去該屬性。
這是一個片段:
$(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'); }); });
.overlay { display: none; } .right { position: absolute; right: 0px; width: 300px; border: 3px solid #8AC007; padding: 10px; } #map { position: relative; /*right: -780px; removed for demo purposes */ width: 452px; height: 344px; background: url(//preview.jesybyqcev4e7b9xn83mzparyiafw29nwvpl11qsrsmunmi.box.codeanywhere.com/BLANK-COMPUTER-SCREEN.png) no-repeat; } #station_A { top: 8%; /* whatever you like */ left: 5%; /* whatever you like */ position: absolute; } #station_B { top: 45%; /* whatever you like */ left: 15%; /* whatever you like */ position: absolute } .hover { color: green }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <div id="map"> <span id="station_A" class="overlay"><img style="background:url(//preview.jesybyqcev4e7b9xn83mzparyiafw29nwvpl11qsrsmunmi.box.codeanywhere.com/BLANK-COMPUTER-SCREEN.png)" src="//lorempixel.com/270/240" /></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>
問題是由於z-index問題,我將圖像移到了前面,並且在更改了CSS之后,按鈕現在可以正常工作了。
#VneckTshirtImage
{
left: 138px;
top: 457px;
position: absolute;
width: 118px;
height: 174px;
z-index:28;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.