Join 149,609 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,868 people online right now. Registration is fast and FREE... Join Now!
intImage = 2; function swapImage(first, second) { switch (intImage) { case 1: intImage = 2 document.getElementById("img1").src = first return(false); case 2: intImage = 1 document.getElementById("img1").src = second return(false); } }
it is just a simple swapImage...basically you click on a smaller image and the larger one loads.
The problem is that sometimes the larger image takes some time to download and there is no activity indicator and for some reason javascript has to load the whole image before it will show it...unlike just loading an image normally (without js) when the image loads from top to bottom and you can see it loading.
So what I would like to do is have the image load normally without having to preload in js. If that is really difficult then a simple gif animated activity indicator while the image is loading to show that something is happening.
Which approach is easiest and how would I go about it.
Any help would be fantastic...I am quite the javascript noob so please forgive any lack of the right vocab or general ignorance in the above.
Well I think we can both agree that large images are going to take some time to download. That is just a fact on the net, even with broadband the data still has to be retrieved. Ideally you would want to go with a preloading in JS to minimize that problem. So here are your options...
1) You can preload with JS so that the user will see the bigger graphics faster and it appear more responsive... but again if they are REALLY HUGE then preloading won't help too much.
2) You can simply think about reducing the filesize of your larger images. Either by cutting down the dimensions or the colors. Sometimes even changing the file type will help you do this (jpg on bigger pictures is better than gif, but gif is better for smaller than jpg). You might also want to limit the number of images on each page if you are doing something like a photo gallery. I find 6 - 8 images are good for each page.
3) You could launch a popup window which would then load the bigger graphic using the classic top down loading style common on the web (like you mentioned).
4) You could put something like a DIV overlay on top of the page that reads "Loading..." and maybe animate the dots, but as far as showing progress that could be a little tough in javascript since javascript doesn't have very good functionality when it comes to reading file sizes on remote machines. Now if you implemented something in AJAX to do this, it would require quite a bit of time and resources which I am not too sure is a good solution to this.
Personally I might do three of the four... reduce the file sizes, preload them, and if the user does click one that isn't fully loaded yet in the preload present the overlay.
However, those are the only real choices you have at the moment. It is up to you and how flexible you are willing to be.
Hope this helps!
This post has been edited by Martyr2: 20 Aug, 2007 - 10:33 AM
Well I think we can both agree that large images are going to take some time to download. That is just a fact on the net, even with broadband the data still has to be retrieved. Ideally you would want to go with a preloading in JS to minimize that problem. So here are your options...
1) You can preload with JS so that the user will see the bigger graphics faster and it appear more responsive... but again if they are REALLY HUGE then preloading won't help too much.
2) You can simply think about reducing the filesize of your larger images. Either by cutting down the dimensions or the colors. Sometimes even changing the file type will help you do this (jpg on bigger pictures is better than gif, but gif is better for smaller than jpg). You might also want to limit the number of images on each page if you are doing something like a photo gallery. I find 6 - 8 images are good for each page.
3) You could launch a popup window which would then load the bigger graphic using the classic top down loading style common on the web (like you mentioned).
4) You could put something like a DIV overlay on top of the page that reads "Loading..." and maybe animate the dots, but as far as showing progress that could be a little tough in javascript since javascript doesn't have very good functionality when it comes to reading file sizes on remote machines. Now if you implemented something in AJAX to do this, it would require quite a bit of time and resources which I am not too sure is a good solution to this.
Personally I might do three of the four... reduce the file sizes, preload them, and if the user does click one that isn't fully loaded yet in the preload present the overlay.
However, those are the only real choices you have at the moment. It is up to you and how flexible you are willing to be.
Hope this helps!
hey Martyr2, thanks for your helpful response.
the filesize is not something easily changed (the max the site allows is 512kb)...it is a community site I built (using open source software and a lot of my own php): http://www.amateurillustrator.com/
I really don't want to do a popup...in fact I actually changed it from the default popup to a swapimage to avoid pop-ups.
I guess what I would like to do is the DIV with loading(and an animated gif on loop)...
What does the code look like to do this (the JS not the html)? and how easy would it be to integrate it into my above code?
The problem is that sometimes the larger image takes some time to download and there is no activity indicator and for some reason javascript has to load the whole image before it will show it...unlike just loading an image normally (without js) when the image loads from top to bottom and you can see it loading.
So what I would like to do is have the image load normally without having to preload in js.
Use the DOM to create a new img element; the browser should load it incrementally, as desired.
I put together an example demonstrating how one might do this [1]; the code will also be posted below for future reference. It seems to work in Firefox 2 and Opera 9. Safari 3 (beta) appears to preload the full‐size image by pre‐parsing the script. Internet Explorer 7’s policy seems to be to always download the image in its entirety before displaying it; you do get a blank image placeholder in the mean time though, so all is not lost. In the process of creating some cursors, I learned something: Internet Explorer requires that cursors be 32×32 pixels; otherwise, it stretches them to those dimensions.
hey, thanks, one thing I found straight away testing this out was that the thumbnail isn't clickable in safari...(safari users make up around 15% of my members).
Safari is now available for pc (still in beta) and I haven't tested it on safari for pc but it may be the same case.
Thanks a lot for your example, it is really appreciated and I will see if I can get it integrated into my code.
hey, thanks, one thing I found straight away testing this out was that the thumbnail isn't clickable in safari...(safari users make up around 15% of my members).
Safari is now available for pc (still in beta) and I haven't tested it on safari for pc but it may be the same case.
I’m using Windows and it works fine in Safari 3.0.3 (beta) on Windows. I have no idea if the Mac beta or Safari 2 work differently. The support table that I use [1] has only sparse information about Safari, so, without owning a Mac or having a more comprehensive support guide, I can’t tell what is and isn’t supported in the versions prior to 3. *
I do recall someone mentioning that another of my scripts didn’t work in Safari 2 in the past; would be nice to pinpoint what that is so that I might avoid it in the future. I thought it might be the media type application/ecmascript, since that was added as the formal ECMAScript (JavaScript) media type only last year, but they said that they changed it and that it made no difference.
* You’ll have to manually enable Safari on that Web site to see the support details for that browser.
hey, thanks, one thing I found straight away testing this out was that the thumbnail isn't clickable in safari...(safari users make up around 15% of my members).
Safari is now available for pc (still in beta) and I haven't tested it on safari for pc but it may be the same case.
I’m using Windows and it works fine in Safari 3.0.3 (beta) on Windows. I have no idea if the Mac beta or Safari 2 work differently. The support table that I use [1] has only sparse information about Safari, so, without owning a Mac or having a more comprehensive support guide, I can’t tell what is and isn’t supported in the versions prior to 3. *
I do recall someone mentioning that another of my scripts didn’t work in Safari 2 in the past; would be nice to pinpoint what that is so that I might avoid it in the future. I thought it might be the media type application/ecmascript, since that was added as the formal ECMAScript (JavaScript) media type only last year, but they said that they changed it and that it made no difference.
* You’ll have to manually enable Safari on that Web site to see the support details for that browser.
If you need some help bug testing the code on safari 2 I will be happy to test it for you.
If Safari 2 has an error console, an error is produced, and you could tell me what the error message is, that might be helpful in performing a Web search on the issue. Otherwise, I wouldn’t bother; it’s hard enough to troubleshoot scripts when you have the browser at your fingertips, much more through when testing through someone else.
If you need some help bug testing the code on safari 2 I will be happy to test it for you.
If Safari 2 has an error console, an error is produced, and you could tell me what the error message is, that might be helpful in performing a Web search on the issue. Otherwise, I wouldn’t bother; it’s hard enough to troubleshoot scripts when you have the browser at your fingertips, much more through when testing through someone else.
Ah well no worries...I couldn't find an error console or error coming up in safari 2...the thumbnail just doesn't seem to be a link...just an image that is not clickable and the cursor stays as a arrow icon instead of becoming a pointer (or hand).
There might be some kind of firebug style development tool out there for safari, I will take a look.
the thumbnail just doesn't seem to be a link...just an image that is not clickable
Maybe Safari 2 doesn’t support DOM2 Events. You could try image.setAttribute("onclick", swap); (DOM2 Core), image.onclick = swap; (DOM2 HTML), or <img … onclick="swap();"> (HTML). When checking this, you would also need to remove the support check for DOM2 Events: Mouse Events that’s in my script.
You might also throw some alert functions in there to see if the script is even being read. If not, the media type should probably be changed to text/javascript.
QUOTE(nickfzx @ 21 Aug, 2007 - 07:58 PM)
and the cursor stays as a arrow icon instead of becoming a pointer (or hand).
Safari 2 may not support the CSS3 Basic User Interface Module (Working Draft) or Microsoft cursor models. CSS2/2.1 don’t allow for the specification of hotspot coordinates, so that might cause the declarations to fail in Safari 2. Or, perhaps, Safari 2 simply doesn’t support custom cursors.
You might try something like the below to test what Safari 2 supports.
CODE
cursor: pointer; /* if custom cursors are not supported */ cursor: url(cursor%20zoom%20in.png), url(cursor%20zoom%20in.cur), pointer; /* if PNG or Windows cursors, but not CSS3 hotspots, are supported */ cursor: url(cursor%20zoom%20in.png) 5 5, url(cursor%20zoom%20in.cur), pointer; /* if CSS3 hotspots and PNG or Windows cursors are supported */
Well, the preloading can be done in a few ways. The best way to make sure is to use img tags immediately after the body tag and make them invisible (style visibility:none); Either that, or use JS to load them. On my WDK I had to handle the preloading to. See http://bluevd.frih.net/template_treegen.php They are loaded by JS. On small sizes it's good to preload with JS. On big sizes, use the img tags with visibility none. As to Safari, well you'll have to remember to check on how the events are handled AND remember that some browsers have their own implementations. This is the best place to check for JS functionality: http://www.quirksmode.org/js/contents.html Also look at the Object Detection section. It has important content. Cheers!