I have a simple plugin made which just adds a flip effect to a div. When we hover over a div we get the div flipped but then when we hover back we get another flip!
I fixed that by adding return: false
in the second parameter function of hover()
in jQuery.
My question is that, is there a better way of stopping from hovering out?
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>
Is there a better way to do it? Or is the only way to do it?
Thanks for any help.