我有在post類中定義的class post和另一個類postinr。我想在班級發佈上鼠標懸停時將活動附加到班級postinr。但我無法做到這一點。解決辦法是什麼。這裏是HTML和JavaScript的結構簡單...`在html中使用javascript在外部類上使用mouseovering添加內部類的事件
var post=document.getElementsByClassName("post");
var postInner=document.getElementsByClassName("postinr");
var i;
for(i=0; i<postInner.length; i++)
{
post[i].addEventListener("mouseover",animate,false);
post[i].addEventListener("mouseout",animate2,false);
}
function animate() {
\t this.style.setProperty("-webkit-transition", "margin-top 2s");
\t this.style.setProperty("margin-top", "70px");
}
function animate2() {
\t this.style.setProperty("-webkit-transition", "margin-top 2s");
\t this.style.setProperty("margin-top", "123px");
}
<div class="post">
<img src="" alt="">
<div class="postinr">
\t <h3></h3>
</div>
</div>
你預計會發生什麼事情沒有發生? –
當鼠標懸停在'.post'上時,你是否希望'.postinr'發生什麼? – divy3993
是的,我想那.. –