change image dimensions with jquery

后端 未结 4 1003
不思量自难忘°
不思量自难忘° 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:36

    Well, to change it, you can just set the image's width() and height():

    $('#myimage').width(700); // Units are assumed to be pixels
    $('#myimage').height(700);
    

    So for you to do the drop down box, you can just set the values to be something like 100x100, 200x200, etc. and split the selected value to extract the dimensions:

    var parts = '100x100'.split('x');
    var width = parseInt(parts[0], 10); // 10 forces parseInt to use base 10
    var height = parseInt(parts[1], 10);
    

提交回复
热议问题