1 回答
TA贡献1808条经验 获得超4个赞
您需要根据可见性风格采取行动。
将 4 个图像放入 HTML 中。
在 CSS 中为他们指定该职位的类别。
对于每个元素,您需要切换,您可以使用这个自制函数toggleImageVisible()。
以下代码片段适用于 2 个按钮:
$(document).ready(function() {
$('#NWest').on('click', function() {
toggleImageVisible('MyImageA');
});
$('#NEast').on('click', function() {
toggleImageVisible('MyImageB');
});
});
function toggleImageVisible(id) {
var img = document.getElementById(id);
img.style.visibility = (img.style.visibility === 'visible' ? 'hidden': 'visible');
}
.container {
position: relative;
top: 0%;
left: 0%;
color: white;
font-size: 20px;
top: 30px;
}
.text {
max-width: 20ch;
position: absolute;
top: 150px;
left: 245px;
transform: translate(-50%, -50%);
}
img {
filter: grayscale(100%);
}
.MyImageClassA{
top: 0px;
left: 0px;
position: absolute;
visibility: hidden;
}
.MyImageClassB{
top: 0px;
left: 75%;
position: absolute;
visibility: hidden;
}
<input type="button" value="North West" id="NWest">
<input type="button" value="North East" id="NEast">
<input type="button" value="South East" id="SEast">
<input type="button" value="South West" id="SWest">
<a href='http://cis337-0217.cisdprogram.com/Index.html'>Return to Index</a><br>
<div class="container">
<img id="MyImageA" class="MyImageClassA" src="MyImage.jpg" alt="MyImage" style="width:25%" ;>
<img id="MyImageB" class="MyImageClassB" src="MyImage.jpg" alt="MyImage" style="width:25%" ;>
<div class="text" id="MyText"> Lines of text. Lines of text. Lines of text. Lines of text. Lines of text. Lines of text. Lines of text.
</div>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报