Get the real width and height of an image with JavaScript? (in Safari/Chrome)

后端 未结 30 3029
傲寒
傲寒 2020-11-22 01:16

I am creating a jQuery plugin.

How do I get the real image width and height with Javascript in Safari?

The following works with Firefox 3, IE7 and Opera 9:

30条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-22 01:35

    Recently I needed to find width and height for setting default size of .dialog representing graph. Solution I use was :

     graph= $('', {"src":'mySRC', id:'graph-img'});
        graph.bind('load', function (){
            wid = graph.attr('width');
            hei = graph.attr('height');
    
            graph.dialog({ autoOpen: false, title: 'MyGraphTitle', height:hei, width:wid })
        })
    

    For me this works in FF3, Opera 10, IE 8,7,6

    P.S. You may be find some more solutions looking inside some plugins like LightBox or ColorBox

提交回复
热议问题