我準備這樣的:當您將鼠標懸停在.container上時,它會更改兩者的顏色。但我只是想改變容器它在鼠標上
當你懸停.container它改變兩者的顏色。但我只是想改變鼠標所在的容器的位置。
這裏是js代碼:
moped = "";
$(".container").mouseenter(function() {
$(".content").css('background', function() {
moped = $(this).css('background');
return "green";
});}).mouseleave(function() {
$(".content").css('background', function() {
return moped;
});
});
HTML:
<div class="container">
<div class="content"></div>
<div class="caption">
<p>This is the caption of .container</p>
</div>
</div>
<div class="container2">
<div class="content"></div>
<div class="caption">
<p>This is the caption of .container2</p>
</div>
</div>
CSS:
.container {
position: absolute;
top: 0;
left: 0;
display: block;
z-index: 800;
width: 250px;
height: 250px;
padding: 0;
margin: 0;
}
.container2 {
position: absolute;
top: 0;
left: 255px;
display: block;
z-index: 800;
width: 250px;
height: 250px;
padding: 0;
margin: 0;
}
.content {
display: block;
background: red;
position: absolute;
z-index: 900;
top: 0;
left: 0;
width: 250px;
height: 250px;
}
.caption {
display: block;
background: none;
position: absolute;
z-index: 1000;
top: 0;
left: 0;
width: 250px;
height: 250px;
}
.caption p {
position: relative;
bottom: 10px;
left: 10px;
}
當你完成其中兩個之後,它是否會讓你從你的小提琴中複製*一小段代碼? – BoltClock