javascript - 如何将变化的图像放在静态图像之上?“img ID”破坏图像位置,“img class”破坏图像变化功能
问题描述
我正在尝试制作一个复制汽车收音机的基本复制 HTML 小工具。现在,我正在尝试在我的静态图像之上制作一个不断变化的图像。一切正常,直到我将它路由到我的函数。
下面的代码可以很好地使用该函数,并且图像会发生变化,但是图像只是转到图像顶部的 0px 0px 而不是 145x62 向内:
<img id="theImage" src="images/First.png">
一旦我将“img id=”更改为“img class=”,图像就会准确地到达我希望它在我的另一个图像之上的位置,但是当我单击“101.1”按钮时,功能会中断并且没有任何变化。
我试过使用 getElementsByClassName ,但也没有用。我目前在墙上,找不到解决方案。
<script src="pause.js"></script>
<script>
function play(){
var audio = document.getElementById("ONE");
ONE.play();
document.getElementById("theImage").src="images/KOSI.png";
document.getElementById('chgID').innerHTML='KOSI-FM';
document.getElementById('chgF').innerHTML='101.1';
document.getElementById('chgCty').innerHTML='Denver, CO';
document.getElementById('chgInf').innerHTML='KOSI 101.1';
}
function playTwo(){
var audioTwo = document.getElementById("TWO");
TWO.play();
document.getElementById("theImage").src="images/KRPX.png";
document.getElementById('chgID').innerHTML='KRPX-FM';
document.getElementById('chgF').innerHTML='95.3';
document.getElementById('chgCty').innerHTML='Wellington, UT';
}
</script>
<audio id="ONE" src="http://live.audio/live" preload="none"></audio>
<audio id="TWO" src="http://live.audio/live" preload="none"></audio>
<img src="main.png" usemap="#image-map">
<map name="image-map">
<area title="ONE" coords="8,328,279,405" shape="rect" onclick="play()">
<area title="TWO" coords="286,326,561,417" shape="rect" onclick="playTwo()">
<area title="THREE" coords="568,328,840,416" shape="rect">
<area title="FOUR" coords="5,417,279,501" shape="rect">
<area title="FIVE" coords="286,417,561,496" shape="rect">
<area title="SIX" coords="564,418,838,493" shape="rect">
</map>
<style>
table, th, td {
border: 1px solid black;
}
</style>
<table align="right">
<tr>
<td></td>
<th></th>
</tr>
<tr>
<td>Station ID:</td>
<td><div id="chgID">XXXX-FM</div></td>
</tr>
<tr>
<td>Freq.:</td>
<td><div id="chgF">00.0</div></td>
</tr>
<tr>
<td>City:</td>
<td><div id="chgCty">City, ST</div></td>
</tr>
<tr>
<td>Info:</td>
<td><div id="chgInf"></div></td>
</tr>
</table>
<style>
img {
position: absolute;
top: 0;
left: 0;
}
.theImage {
z-index: 1;
position: absolute;
top: 145px;
right: 62px;
}
</style>
<img class="theImage" src="images/First.png">
解决方案
推荐阅读
- chrome-web-store - 无法发布到 chrome 网上商店
- python - 用python进行高斯分布的蒙特卡罗方法
- javascript - FormData 使用 axios 发送空数据
- r - 在R中的knn中实现距离矩阵
- linux - hashcat - 切换大小写字典攻击(区分大小写)
- voip - 如何解决国际代码前缀?
- python - 我可以从 Rouge 调用结果返回的一部分吗?
- java - 如果有这样的错误,我必须编写代码来改进它
- c# - No-iusertokenprovider-is-registered 问题
- python - 如何将具有不同数量元素的多个列表转换为csv文件