View Full Version : Another CMotion Image Gallery Question!

11-06-2006, 12:26 AM
1) Script Title: CMotion Image Gallery

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/cmotiongallery.htm

3) Describe problem: Well, not a problem at all......just a couple of little bits!

Evening you wonderful load of people - I could just kiss Dynamic Drive all over for supplying some top-notch scripts for me to play with. My latest toy is the CMotion Image Gallery with which I'm incredibly pleased - got it looking just how I want it and it'll do as it is but..............just a couple of questions.

Firstly, I have a large number of images and hence a large number of popup windows - is it possible to change (preferably in JavaScript rather than creating individual html files for all images) the background colour of the popup window?

Secondly, is it possible to set the popup window to automatically resize to the size of the image (some are portrait, some are landscape) instead of it being a fixed constant? If this can be done then I won't really be needing the answer to my first question!

Thirdly, if the resizing isn't possible.....how about a centering for the image?

Fourthly (and finally, you'll be glad to hear!), how about the images loading as they're downloaded - it's a bit of a pain having to wait every time for all of the images to download before they're all displayed.

Like I say, I'm happy with the script as it is - atfer all, it's live - but if something can be done about any or all of the above then I'd be ever so grateful! Whenever you're ready - no rush!!!

Many thanks once again for a bundle-load of great scripts!


11-06-2006, 04:31 AM
Yes, after a fashion, the same script function that you use to create the pop-up can also create a page for it to contain. You can pass parameters to this function (enlargeimage already accepts):

path, optWidth, optHeight

to tell it what background, size, etc. you want and a great many other things, depending upon how you (re)write it. I customized such a function starting with Eric King's Popup Window Generator wizard (http://www.dynamicdrive.com/dynamicindex8/popwin.htm) (which at that time was called Auto center window script) for a site I master, you can see my modifications in action (and view the source) here:


Now, I did say after a fashion. There are problems with automatically sizing a window, not the least of which is that many browsers simply won't allow it to begin with, automatic or otherwise, some won't even allow pop ups at all. Most will however. The next big hurdle is that to be truly 'automatic', the dimensions of the image must be gotten somehow. That somehow is via preloading or, you can cheat and just tell the function what the image's dimensions are. Cheating is generally best as, there is never any guarantee that preloading will be accomplished in time except via a loop that keeps checking and this can really bog everything down on a slow connection and may not work out too well in certain cases, making the script less accessible than it already is. This means you must pass the dimensions for each image, tedious but, effective.

This bit about image dimensions is also the solution to loading the gallery in the first place. Cmotion requires that it know the width dimension of the image train before it can load successfully. If you tell it the dimensions of each image it is loading, it doesn't have to wait for them to load and could therefore be rewritten to load before the images have loaded. But, there will be images that are not there at first, even though broken image placeholders will occupy their layout space until they do load.

You can always speed loading of the actual images for a gallery of this sort by optimizing and cropping and/or resizing (down) the gallery images so that they are all of a smaller byte size.

Also, since images are basically already preloaded locally, one can get javascript itself to write out their dimensions for you locally in a convenient form to cut and paste into your code for later use on the live page. This one is beyond just a little tricky for a novice so I will post code later on in this thread for this.

In any event, this is quite a bit of a project so, I am hoping that you may be able to get some of it worked out, perhaps with someone else's help, from what I've told you, then I could step in later to solve any glitches that may remain.

I would also invite other coders in these forums to lend a hand. With enough of us working together, the work would be lighter for each and, it could be fun!

11-06-2006, 06:46 AM
As promised, here is a link to a thread that will do some of the heavy lifting when it comes to writing your function calls:


particularly post #6 but, to get a real idea of how to do this, you should probably read the entire thread at least up to and including that post.