你想要可以實現的,但你需要刪除:hover selector
和使用,作爲css animation
什麼。另一種方法是使用jQuery mouseenter event
。
使用CSS動畫和刪除hover selector
。
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
.move{
-webkit-animation:mv 2s;
animation-fill-mode:forwards;
}
@-webkit-keyframes mv{
from{
transform: translate(0,0) rotate(0deg);
}
to{
transform: translate(-350px,0) rotate(-360deg);
}
}
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
另一種方法是使用jQuery的MouseEnter事件,執行相同的css animation
,但你停在新位置的元素。
$(document).ready(function(){ \t
\t $("#twit").on("mouseenter",function(){
$("#twit > .object").addClass("nwmv");
});
});
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
.nwmv{
-webkit-animation:mvv 2s;
animation-fill-mode:forwards;
}
@-webkit-keyframes mvv{
from{
transform: translate(0,0) rotate(0deg);
}
to{
transform: translate(-350px,0) rotate(-360deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
使用JavaScript,
var b = document.getElementById("twit");
b.onmouseenter = function mv(){
var a = document.querySelector(".move");
a.style.transition = "2s ease";
a.style.transform = "translate(-350px,0) rotate(-360deg)";
}
.object{
position:absolute;
}
.bird{
top: 50%;
left: 64%;
}
<div id="twit">
<div class="object bird move">
<img width="50px" height="50px" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ0rasMS9P_knjCI0jPS2S3EavRVR57YSoOJSomU3tcmaxV_zom5cZWOg">
<b>Welcome Home</b>
</div>
</div>
你到底這個是什麼意思?你能詳細說明一下嗎? –
當我懸停圖像時,圖像移動到左側,我希望它留在它移動到的新位置(它必須留在左側),當我移動指針時。我對這個概念很陌生,幫幫我。 – Gowtham
使用:hover psuedo,一旦將光標移開,它將回退到原來的位置,它不可能只用css「粘」在那裏。 – Ricky