You have to specify the image source, otherwise you are loading
nothing.

The code should read:
var $img0 = $("<img src='your-image-source-here.jpg'>").load( ......

Charles

On Oct 2, 9:55 am, BAlex <[EMAIL PROTECTED]> wrote:
> Has made:
>
>     var width, height;
>     var img0 = $("<img>").load(function(){
>                             width = $(this).width();
>                             height= $(this).height();
>                       }).attr("src", "1.jpg");
>     alert("//--> img0=" + img0 + ", w=" + width + ", h=" + height);
>
> Has received: //--> img0=[object Object], w=0, h=0
>
> :-((
>
> On 2 окт, 18:25, Flesler <[EMAIL PROTECTED]> wrote:
>
> > You want to save the real height/width to a variable, or to set it
> > programatically? if you want to retrieve the real attributes you will
> > need to check, only after the image has loaded (on the event onload):
> > something like this.
>
> > var width, height;
> > var $img = $('<img'>)
> >                       .load(function(){
> >                             width = $(this).width();
> >                             height= $(this).height();
> >                       })
> >                       .attr('src','1.jpg');
>
> > the var $img part is in case you need the image afterwards, else you
> > can ommit that. Bear in mind that you won't know when will that
> > happen, so you can count on the variables to be filled right after
> > this snippet, you should probably make everything inside the function.
>
> > If what you wanted to do is the opposite, then:
> > var img = new Image();
> > img.width = 123; //any number you want
> > img.height = 123; //any number  you want
> > img.src = "1.jpg";
>
> > ( oh... I'm no expert :) )
>
> > I hope that was more or less your situation.
>
> > On Oct 2, 8:24 am, BAlex <[EMAIL PROTECTED]> wrote:
>
> > > Is JavaScript:
>
> > > var img = new Image();
> > > img.src = "1.jpg";
> > > var width = img.width;
> > > var height = img.height;
>
> > > It is necessary for preliminary loading image and, the main thing, for
> > > preliminary definition width and height.
>
> > > How same to represent on jQuery?
>
> > > In advance thanks,
> > > Alexander- Скрыть цитируемый текст -
>
> > - Показать цитируемый текст -

Reply via email to