我目前正在开发一个项目,需要通过使用相对于每个角的按钮将图像移动到屏幕的每个角。图像从左上角(西北)开始,然后通过单击东北按钮,它会移动到右上角等。即使我通过在按钮中添加警报来确认按钮工作,我似乎也无法让图像移动。图像上显示的文本我也需要随图像一起移动,但此时我只专注于让图像移动。任何帮助,将不胜感激。
HTML:
!DOCTYPE html>
<html lang = "en">
<head>
<title> Paragraph over image centered </title>
<meta charset = "utf-8">
<style>
.container{
position: relative;
top: 0%;
left: 0%;
color: white;
font-size: 20px;
}
.text {
max-width: 20ch;
position: absolute;
top: 150px;
left: 210px;
transform: translate(-50%, -50%);
}
img {
filter: grayscale(100%);
}
</style>
<script src="ParagraphOverImageWithButtons.js"></script>
</head>
<body>
<div class="container">
<img id="MyImage" src="MyImage.jpg" alt="MyImage" style="width:25%;">
<div class="text"> Lines of text Lines of text Lines of text Lines of text
Lines of text Lines of text Lines of text Lines of text Lines of text
</div>
</div>
<input type="button" value="North West" onclick="NWfunction()">
<input type="button" value="North East" onclick="NEfunction()">
<input type="button" value="South East" onclick="SEfunction()">
<input type="button" value="South West" onclick="SWfunction()">
<a href='http://cis337-0217.cisdprogram.com/Index.html'>
Return to Index
</a>
</body>
</html>
JS:
function NWfunction(){
document.getElementById("MyImage").style.top="150px";
document.getElementById("MyImage").style.left="210px";
}
function NEfunction(){
document.getElementById("MyImage").style.top="150px";
document.getElementById("MyImage").style.left="1500px";
}
function SEfunction(){
document.getElementById("MyImage").style.top="1500px";
document.getElementById("MyImage").style.left="1500px";
}
function SWfunction(){
document.getElementById("MyImage").style.top="1500px";
document.getElementById("MyImage").style.left="210px";
}
繁花如伊
皈依舞
相关分类