8
我有以下圖像:跨瀏覽器的動畫gif在懸停和反轉時鼠標離開
Static Image | Starting Animation | Ending Animation
,我使用下面的代碼(jsfiddle example):
$(function() {
$("#link-gif").hover(
function() {
/* starting animation */
$(this).css("background-image", "url('http://i.imgur.com/HhsBws5.gif')");
},
function() {
/* ending animation */
$(this).css("background-image", "url('http://i.imgur.com/WLFzz3S.gif')");
}
);
});
#link-gif {
width:150px;
height:40px;
border:1px solid #39464E;
background-image:url('http://i.imgur.com/YgLJoVH.png'); /*static*/
background-size:contain;
background-repeat:no-repeat;
background-position:bottom center;
cursor:pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="link">
<div id="link-gif"> </div>
</div>
因此,在總結,我希望發生的是:我首先加載靜態圖片。當有人將鼠標懸停在#link-gif
上時,開始的動畫gif開始播放,當您將其懸停時,結束動畫開始。
出於某種原因,當您將鼠標懸停在圖像上時,圖像不會生成動畫。它只是到了gif的結尾。有誰知道爲什麼會發生這種情況?
你真的無法控制在任何瀏覽器GIF動畫。 – adeneo
@adeneo嗯,我只是試圖成功顯示懸停的動畫GIF。我的意思是任何事情都有可能吧;) – bryan
完美地適合我 – Turnip