基本上我正在做的是製作一個「查看更多」類型的東西。我有一段文字描述了我所做的工作,並在段落末尾有一個按鈕。我(這是一個真正的鏈接,帶有按鈕樣式)。當按鈕被按下時div會擴大到400px,而額外的文字會被添加.html();但是當我點擊「查看少」按鈕折回到較小的段落和200px div時,沒有任何反應。jquery使用按鈕動畫高度變化
jQuery的
$(document).ready(function(){
var $mottheight = $('#row-mott').height();
if ($mottheight == 300) {
$('#mott-btn-collapse').click(function(){
$('#row-mott').animate({
height:200
}, 300);
$('#mott').html('I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. <a href="#" id="mott-btn" class="btn btn-mini">Less info »</a>');
});
}
else if ($mottheight < 300){
$('#mott-btn').click(function(){
$('#row-mott').animate({
height:300
}, 400);
$('#mott').html('I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. I\'ve worked on the Warren Mott High School website since September of 2011. I am one of four student webmasters that keep the website in the best condition possible. We cannot take credit for all the coding, though. This website is run by around 40 Web Design students. As Webmaster, my job is to fix, improve, and help those students learn as they go. <a href="#" id="mott-btn-collapse" class="btn btn-mini">Less info »</a>');
});
}
else {
return 0;
}
});
請記住,代碼是在加載時執行的。當頁面加載第一個if語句爲false時,所以點擊綁定永遠不會被加載。 – 2013-04-25 17:33:44