www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] OnMouseOver image loading works only 2nd time

  1. #1
    Join Date
    Aug 2010
    Location
    Hungary
    Posts
    2

    resolved [RESOLVED] OnMouseOver image loading works only 2nd time

    Hi,
    I use DIV tags with onMouseOver action on the DIV-s. I want to download and show a photo if an onMouseOver activates. This is simple and works but there is a problem.

    First time I move my mouse cursor on the DIV the photo doesn't appear, only its border. When I move the mouse off and back again, the photo appears right. I want to show the photo first time well.

    There is a solution: preloading images with JavaScript invoked with the onLoad event of the BODY tag. But I would have numerous (100+) photos, so it's a bad idea to preload all the photos (and users usually want to see only a few, not all of them). It is acceptable to wait a second or two after activating onMouseOver while the photo is downloading but it's not acceptable to do TWO onMouseOver actions for a photo.

    The testpage with only five photos: http://teszt8.elin.hu/proba/

    The problem when I move the mouse cursor on a DIV first time: http://teszt8.elin.hu/proba/hiba.jpg (Only the border appears, the photo doesn't.)

    After the browser downloads the photos it works well for some minutes or for the next browser restart. I've tried with IE8 and Firefox 3.6.8, works bad with both.

    Please help, what's the solution?

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Code:
    function showimage(image, show, e) {
    // Download image:
    var newImg2 = new Image();
    newImg2.src = image;
    var imageheight = newImg2.height;
    var imagewidth = newImg2.width;
    You have a preloading function that you choose not to use.
    This means that when you try to get the dimensions of the image, it has not loaded, so the height and width are probably zero, which will cause an error when later you use those values as divisors.

  3. #3
    Join Date
    Aug 2010
    Location
    Hungary
    Posts
    2
    That's right, this is the problem! Really thank you, have a nice day!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles