我有一個簡單的插件,只是增加了對div的翻轉效果。當我們將鼠標懸停在div上時,我們會將div翻轉,但當我們將鼠標懸停時,我們會再次翻轉!什麼是避免影響懸停的更好方法?
我修正了在jQuery中hover()
的第二個參數函數return: false
。
我的問題是,有沒有更好的停止懸停的方法?
JS:
$.fn.jflip = function(bgimage) {
var img = bgimage;
this.hover(function(){
$(".fake").animate({
top: '+=200px'
}, 500);
$(".fake1").animate({
top: '-=200px'
}, 500);
$(".fake").delay(300).animate({
top: '-=200px'
}, 500);
$(".fake1").delay(300).animate({
top: '+=200px'
}, 500);
}, function(){
return false;
});
}
HTML + CSS:
.flipper {
background: url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSMMSb5XY_fztmTj2rSwFNn-nw2zxId1ZJLnuFfy39Rk-g2fHZ1) no-repeat;
background-size: 98% 98%;
background-position: 4px 4px;
width: 400px;
height: 400px;
background-color: #eee;
}
.fake {
position: relative;
top: -200px; left: 0;
height: 200px;
width: 400px;
background-color: white;
}
.fake1 {
position: relative;
top: 200px; left: 0;
height: 200px;
width: 400px;
background-color: white;
}
<body>
<div class="flipper">
<div class="fake" /></div>
<div class="fake1" />
</body>
有沒有更好的方法來做到這一點?或者是唯一的方法呢?
感謝您的幫助。
我建議你先學會跳進DOM操作使用JavaScript –
@ RokoC.Buljan我們可以關閉的div像< /><之前關閉HTML標籤 - 這:) –
@MohammadAreebSiddiqui在正確的html中沒有自閉合div標籤,而'flipper'類的div標籤根本沒有關閉。 – Sumurai8