JavaScript jQuery Animate
Hi i have done a code that i need to toggle. How can i do it with this code?
var divh = document.getElementById('first').offsetHeight;
document.getElementById("first").style.heig开发者_Python百科ht = "100px";
$("div:first").click(function(){
$("#first").stop().animate({
height: divh
}, 1000 );
});
If I correctly understand, you want to toggle height of the div from it's current state to 100px and backward. So why don't you want to use .toggle() method instead? Like this:
//keep default height
var divh = $('#first').outerHeight();
//toggle functions
$('div:first').toggle(
function () {
$('#first').stop().animate({
height: divh +'px'
}, 1000);
},
function () {
$('#first').stop().animate({
height: '100px'
}, 1000);
}
)
精彩评论