これを試して:
// BTW, if you're using newer jQuery and no other library that namespaces the $ symbol,
// you can replace that long document.ready line with the following:
// $(function() {
jQuery(document).ready(function(e){
// call just one click function
$('.plussign').click(function(e) {
// using toggle function will allow you to operate between the two clicks
$(this).toggle(function(e) { // click odd
// If both elements are recieving the same action, then call them in the same line,
// simply seperate with a comma
$('#bigdiv, .plussign').stop().animate({height : '400px'}, 200);
// the .stop() function will stop any previous animation and continue with the new,
// this is usefull for FAST CLICKING
},
function(e) { // click even
$('#bigdiv, .plussign').stop().animate({height : '80px'}, 200);
});
});
})
でも
基本クラスとトグルクラスを使用し、jQueryの.toggleClass機能を使用することをお勧めします。これは、コーディングがはるかに少なく、cssを簡単に調整できるという点で制御が簡単だからです。例えば:
CSS
.open {
height: 400px;
}
.closed {
height: 80px;
}
脚本
$(function() {
// if you dont add the closed class to the html element itself on the HTML,
// you can add it here before setting your click event
$('#bigdiv, .plussign').addClass("closed");
// then set your click event with the toggleClass function
$('.plussign').click(function(e) {
$('#bigdiv, .plussign').toggleClass("open closed");
// if you add jQueryUI to the mix you can control the speed in time as follows
// $('#bigdiv, .plussign').toggleClass("open closed", 10000);
});
})