2012-05-24 73 views
1


我帶着另一個問題jQuery的:
所以我有這樣的代碼:
jQuery的:點擊放大和移動

$(document).ready(function(){ 
$(this).click(function(){ 
    $("#block1").animate({width:7em,height:7em}); 
    $("#block2").animate({width:7em,height:7em}); 
    $("#block3").animate({width:7em,height:7em}); 
    $("#block4").animate({width:7em,height:7em}); 
    $("#block5").animate({width:7em,height:7em,function(){ 
     $(this).animate({width:20em,height:20em,top:4em,left:8em}); 
    }); 
}); 
}); 

是應該得到一些「便利貼」形盒子到
1:讓所有的箱子回到原來的位置和大小
2:彈出他們的原始位置去屏幕中間,而放大時點擊..
你有什麼想法爲什麼這個不起作用? (我不想要一個CSS懸停,但如果有另一種方式,通過CSS做到這一點,我沒事吧!!)

+0

爲什麼要將'click'處理程序綁定到文檔? –

+0

我的第一個問題是您的方法調用不太正確。 '.animate({width:7em,height:7em)};' - 括號的方式是錯誤的。 – ahren

+0

hehe ..好吧,我的主要目標是將它綁定在我點擊的5個塊中的任何一個上。不完全按照這種方式工作,right,=) – BDdL

回答

3
$(document).ready(function(){ 
    $(this).click(function(){ 
    $("#block1").animate({width:"7em",height:"7em"}); 
    $("#block2").animate({width:"7em",height:"7em"}); 
    $("#block3").animate({width:"7em",height:"7em"}); 
    $("#block4").animate({width:"7em",height:"7em"}); 
    $("#block5").animate({width:"7em",height:"7em"},function(){ 
     $(this).animate({width:"20em",height:"20em",top:"4em",left:"8em"}); 
    }); 
    }); 
}); 

1)中第7行缺少一個右括號 「$(」 #塊5 「)動畫({寬度:」 7em 「高度: 」7em「 '}',函數(){」

2)也ü需要包括jQuery的文件

3)動畫u需要給予高度和寬度比元素的當前高度和寬度看即比7em更多的作用,如CSSü已經給出7em

4)也沒有給予元素,因爲我發現你的jsFiddle鏈接

以上提到的所有內容均基於您給出的鏈接http://jsfiddle.net/q5RwE/2/

+0

謝謝!對不起我在jsfiddle中失蹤的幾件事,你的回答是完美的! ;)+1和投票 – BDdL

+0

歡迎:) – Uttara

1

改變你的代碼是這樣的

.animate({寬度: 「7em」,高度: 「7em」});