我在頁面上有兩個圓圈,如果我將鼠標懸停在circle1上,右邊第二個圓圈(circle2)放大。我正在嘗試使用jquery讓circle2做同樣的事情,但是兩個圓形閃光燈和circle2都被誤放了。jquery - 如何在鼠標懸停上增長/縮小圖像
下面是HTML我到目前爲止
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="practice.css">
<title>Practice</title>
</head>
<body>
<div class="container">
<div class="circle1" id="circle1"></div>
<div class="circle2" onmouseover="growCircle()" onmouseout="shrinkCircle()"></div>
</div>
<script>
function growCircle() {
document.getElementById("circle1").className = "circleBig";
}
function shrinkCircle() {
document.getElementById("circle1").className = "circle1";
}
</script>
</body>
</html>
這是我的CSS
.body {
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 0px auto;
height: 500px;
background:#CC0000;
display:block;
}
.circle1 {
width: 300px;
height: 300px;
border-radius: 50%;
background: #dadada;
/* position: absolute; */
/* top: 50%; */
/* left: 30%; */
/* margin-right: -50%; */
/* transform: translate(-50%, -50%); */
float:left;
}
.circle1:hover + .circle2 {
width: 500px;
height: 500px;
}
/* .circle2 {
width: 300px;
height: 300px;
border-radius: 50%;
background: #000000;
position: absolute;
top: 50%;
left: 50%;
float: right;
transform: translate(-50%, -50%);
} */
.circle2 {
width: 300px;
height: 300px;
border-radius: 50%;
background: #dadada;
/* position: absolute; */
/* top: 50%; */
/* left: 30%; */
/* margin-right: -50%; */
/* transform: translate(-50%, -50%); */
float:right;
}
.circleBig {
width: 500px;
height: 500px;
border-radius: 50%;
background: #dadada;
}