View Full Version : Cmotion Gallery Mozilla Bug

06-26-2005, 06:43 AM

It seems that if this script is used on a page with most doctypes and the width of the train of images displayed is greater that the window width, Mozilla will default to a rough equivalent of window.innerWidth when calculating the 'actualwidth' variable used for determining how far to scroll left before reaching the end of the image train. This results in the scrolling stopping short of displaying all the images. I came up with an alternate method for calculating this width but, I had to use a 'cosmological constant' to get it to work right, here is the function I came up with:
function findWidth(){
var combWidth=0
var inc=-1
var docImages=document.getElementsByTagName('img')
for (i = 0; i < docImages.length; i++){
if (docImages[i].parentNode.parentNode.parentNode.id=='motiongallery'){
combWidth+=(inc)*4 // 'cosmological constant'
return combWidth
}This 'cosmological constant' represents the additional space between image elements after their borders have already been taken into account. I don't know where it comes from exactly, or how to access it more directly. Any thoughts?

Anyways, to my surprise, this function also worked in IE and Mozilla with or without a doctype!

Added Later:

That 'cosmological constant' was bothering me, so after a trip to the DOM inspector, I realized that it was partly to be accounted for in the borders of the anchor elements containing the images. I also noticed that there was another element between the images and the id'd container, the <nobr> element. I then discovered that if this element was given an id and accessed for its offsetWidth, it returned the correct value. Therein lies the real fix for this script. Give that <nobr> tag on the display page an id and access its offsetWidth in the script to get the actualwidth variable.

06-27-2005, 09:28 AM

Gives a simpler explanation of the fix. Also, all the code in the script creating and referring to the span with the id of 'temp' can be removed.

06-27-2005, 11:37 PM
Very nice jscheuer1! Thanks for tirelessly investigating and posting a fix. I'll test out the code referred to in your other thread, along with another idea I have for overcoming the problem, and update the script once that's done.


07-12-2005, 07:58 AM
I've gone ahead and updated the script with the fix as suggested by jscheuer1 in this thread. (http://www.dynamicdrive.com/forums/showthread.php?p=11490) Thanks again for the code. :)