【问题标题】:If image size javascript condition is ok show div如果图像大小 javascript 条件正常,则显示 div
【发布时间】:2013-11-24 11:02:55
【问题描述】:

我需要一些帮助。我试图在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});

所以我需要这样的东西

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

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

);

但我不知道如何写这个条件。请帮帮我。

当 image1 调整为高度 240 和宽度 107 时,是否有可能自动显示 image2 ?

谢谢

对不起,我的英语不好。

【问题讨论】:

    标签: javascript jquery html css jquery-ui


    【解决方案1】:
    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()
           }
        }
    });
    

    【讨论】:

      【解决方案2】:

      条件是:

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

      【讨论】:

        【解决方案3】:

        希望对你有帮助

        $('#image1').on('click',function(){
        
           if($('#image1').width() == 107 && $('#image1').height() == 240) {
        
              $('#image2').show()
           }
        
        );
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-09-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-13
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多