change image dimensions with jquery

后端 未结 4 1005
不思量自难忘°
不思量自难忘° 2021-01-18 00:19

I have a image under div id myimage. Now I want to resize it by using change. I want from select box if selected 700X7000 then image\'s size will be height 700px and width 7

4条回答
  •  爱一瞬间的悲伤
    2021-01-18 00:52

    The condition is where you can say item selected.

    if( condition ) {
       $('div#myimage img').css({'width' : '700px' , 'height' : '700px'});
    }
    else {
       $('div#myimage img').css({'width' : '150px' , 'height' : '150px'});
    };
    

    Below are ways to check to see if the box is selected:

    // First way 
    $('#checkBox').attr('checked'); 
    
    // Second way 
    $('#checkBox').is(':checked'); 
    

    Example working:

    if( $('#checkBox').attr('checked') ) {
       $('div#myimage img').css({'width' : '700px' , 'height' : '700px'});
    }
    else {
       $('div#myimage img').css({'width' : '150px' , 'height' : '150px'});
    };
    

提交回复
热议问题