2013-11-24 75 views
3

我需要一些幫助。我試圖做一個JavaScript的條件來顯示一個div後,對象被調整大小,並有我需要的寬度和高度。如果圖像大小javascript的條件是確定顯示div

這是我的代碼

HTML

<img id="image1" src="img/object1" width="107" height="30"> 
<img id="image2" src="img/onject1" width="107" height="240"> 

的Javascript

$("#image2").hide(); 
$("#image1").resizable({ maxHeight: 240 , maxWidth : 107 , minWidth: 107}); 

所以我需要somethimg這樣

$('#image1').click(function(){ 

if $('#image1') have height 240 and width 107 
show $('#image2') 

); 

但我不知道怎麼寫這種情況。請幫幫我。

當image1被調整到高度240和寬度107時,是否有可能自動顯示image2?

謝謝

對不起,我的英語不好。

回答

3
if($('#image1').width() == 107 && $('#image1').height() == 240){ 
    $('#image2').show() 
} 

如果用想車展,在調整大小事件中使用event-resize

$("#image1").resizable({ 
    maxHeight: 240 , 
    maxWidth : 107 , 
    minWidth: 107, 
    resize: function (event, ui){ 
     if($('#image1').width() == 107 && $('#image1').height() == 240){ 
     $('#image2').show() 
     } 
    } 
}); 
+0

大, 非常感謝你 –

2

的條件是:

 
if ($('#image1').height() == 240 && $('#image1').width() == 107) { 

    $('#image2').show(); 

} 
2

希望它會幫助你

$('#image1').on('click',function(){ 

    if($('#image1').width() == 107 && $('#image1').height() == 240) { 

     $('#image2').show() 
    } 

); 
相關問題