Find out what the width of an image is using jQuery

前端 未结 2 802
难免孤独
难免孤独 2021-01-25 02:03

I have these images that I am getting off my server and a database using PHP

2条回答
  •  不思量自难忘°
    2021-01-25 02:20

    I would try .innerWidth() instead of .width(), as .width() would include the margin.

    $('img').innerWidth();
    

    If your image is really that big, you should consider scaling it down it server-side.

    Update

    Actually .width() is not adding the margin and furthermore its not even adding the padding. That makes .width() more suitable than .innerWidth(). Thanks SKS.

提交回复
热议问题