【发布时间】:2021-08-15 07:49:14
【问题描述】:
我需要通过init() 重新定位此 HTML 代码中的 5 个方块
函数和reposition() 函数。
我看着另一个
网站的 HTML/CSS 主题,但我什么也没找到
对这些信息很有帮助。
以下是问题:
A.在
init()函数中添加所需的代码reposition()将鼠标悬停在 与 CSS 类“square”关联的页面元素。B.修改“重新定位”功能,使其允许您 重新定位正方形相对于对角线对称。要做 这个,只需颠倒这个的水平和垂直位置 正方形。
注意:粉色方块不会移动,因为它正好在对角线上(水平和垂直位置相同)。
这是我的起始代码:
<!DOCTYPE html>
<html lang="fr"
<head>
<meta charset="UTF-8">
<title>Reposition the squares</title>
<style>
#bac {
position: relative;
width: 400px;
height: 400px;
border: 1px solid red;
text-align: center;
}
.square {
width: 50px;
height: 50px;
}
#carre1 {
position: absolute;
left: 300px;
top: 200px;
background-color: red;
}
#carre2 {
position: absolute;
left: 120px;
top: 75px;
background-color: blue;
}
#carre3 {
position: absolute;
left: 50px;
top: 240px;
background-color: orange;
}
#carre4 {
position: absolute;
left: 350px;
top: 0px;
background-color: black;
}
#carre5 {
position: absolute;
left: 50px;
top: 50px;
background-color: pink;
}
</style>
<script>
function init() {
}
function reposition() {
}
</script>
</head>
<body onload="init()">
<h1>Reposition the squares</h1>
<div id="bac">
<div id="carre1" class="square"></div>
<div id="carre2" class="square"></div>
<div id="carre3" class="square"></div>
<div id="carre4" class="square"></div>
<div id="carre5" class="square"></div>
</div>
</body>
</html>
【问题讨论】:
-
您好,您知道如何添加事件监听器吗?
-
是的,有点,但我不知道如何解决这个问题。