jQuery Animate toggle
I am trying to create an animate effect like the following.
// JavaScript Document
$(document).ready(function () {
$('.lovebtn').click(function () {
$('.love').animate({
height: '672px'
}, 1000, function () {
$('.lovetxt').css("display", "block");
$(".lovebtn .button").attr("src", "images/btn_love_close.gif");
});
});
// Lust
$('.lustbtn').click(function () {
$('.lust').animate({
height: '672px'
}, 1000, function () {
$('.lusttxt').css("display", "block");
$(".lustbtn .button").attr("src", "images/btn_lust_close.gif");
});
});
//luxuary
// Lust
$('.luxurybtn').click(function () {
$('.maskbg').css("display", "block");
$('.luxury').animate({
height: '1056px'
}, 1000, function () {
$('.luxurytxt').css("display", "block");
$(".luxurybtn .button").attr("src", "images/btn_luxury_close.gif");
});
});
});
http://uniquedl.com/3closets/index.html
when you go the the ablove page and click开发者_JS百科 the three buttons on either love lust and luxury. you get a series of effects. when i click the same button i wannt reverse the effect .
any tips how i can do it ?
I will show only for the love buttonm almost the same for other just different height and CSS selectors of course
$('.lovebtn').click(
$('.love').toggle(
function() {
$('.love').animate({
height: '672px'
}, 1000, function () {
$('.lovetxt').css("display", "block");
$(".lovebtn .button").attr("src", "images/btn_love_close.gif");
}
},
function() {
$('.love').animate({
height: '480px'
}, 1000, function () {
$('.lovetxt').css("display", "none");
$(".lovebtn .button").attr("src", "images/btn_love_open.gif");
}
}
);
);
Sorry I have problems putting the code in right layout :( You could check it here http://jsfiddle.net/dKyku/
Basically on clicking the link you toggle between two portions of code, one showing the section, and second one hiding it/putting it back to its original layout.
You can also do this by adding extra class like this
$('.lovebtn').click(function (){
if (!$(this).hasClass('reverse')) {
hasClickedLove = true;
$('.love').animate({
height: '672px'
}, 1000, function () {
$('.lovetxt').css("display", "block");
$(".lovebtn .button").attr("src", "images/btn_love_close.gif");
});
$(this).addClass('reverse);
}//end if
else if(hasClass('reverse')) {
$(this).removeClass('reverse);
//animation code
}
});
Insert a boolean value, like this:
$('.lovebtn').click(function () {
if ( !hasClickedcLove) {
hasClickedLove = true;
$('.love').animate({
height: '672px'
}, 1000, function () {
$('.lovetxt').css("display", "block");
$(".lovebtn .button").attr("src", "images/btn_love_close.gif");
});
}//end if
else {
hasClickedLove = false;
//animation code
}
});
精彩评论