aldobranti
06-14-2012, 02:14 PM
1) Script Title: cmotion
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/cmotiongallery.htm
3) Describe problem: Chrome appears to fix trueContainer offsetWidth before loading images.
4) Sample Site (use Chrome ) : http://aldobranti.eu/#!photography/beaches/P9260355
JScheuer, I have used your cmotion library a number of times and it has given me many opportunities to learn more about JS. Thank you.
I have been working on a do-it-yourself content management system where I get the server side to tell me about image files in a directory and then I populate one of your cmotion controls with a rolling display of thumbnails. The xhr sends returns to the client with a pile of javascript declarations with which I build the contents of trueContainer; here is my xhr call
function galleryRequest(dir,fil,failure) {
"use strict";
var request2= makeHttpObject();
var Y = document.getElementById("trueContainer");
while (Y.childNodes.length){ Y.removeChild(Y.firstChild) };
request2.open("GET","./imageGallery2.php?path="+dir+"/"+fil,true);
request2.send(null);
var myHandler = new Event();
myHandler.addHandler(fillup);
request2.onreadystatechange
= function(){
if(request2.readyState == 4){
if(request2.status == 200) {
gallery = new Array();
//Y.innerHTML = request2.responseText;
doScripts( request2.responseText); // evals the returned JS into an array gallery of objects if ( gallery.length ) {
var frag = document.createDocumentFragment();
for (var g=0;g<gallery.length;g++){
var a = document.createElement('a');
a.href = gallery[ g].href;
var i = document.createElement('img');
i.src = gallery[ g].src;
i.alt = gallery[ g].alt;
i.title = gallery[ g].alt; // i.style.width='48px'; /* totally gross hack */
a.appendChild( i);
frag.appendChild( a);
}
Y.appendChild( frag);
}
myHandler.execute();
} else if (failure) failure(request2.status, request2.statusText)
}
};
}
This works well in FF Safari IE8 and Opera but not in Chrome.
From what I can see trueContainer.offsetWidth (Chrome ) is reporting values like 10 and 20 which seem closer to the accumulated padding of the images while the other browsers report the accumulated image widths.
From the code you'll see that I have picked up on suggestions made to people reporting similar problems in ajax :
• I tried your OO cmotion but it didn't fix Chrome's view of offsetWidth
• I don't use innerHTML
• I use a document fragment to save hitting the DOM
• I use an event to call 'fillup' so that the DOM can redraw before I query offsetWidth
• not shown but have tried a span rather than the nobr
• I don't use jquery because I really want to learn raw JS ( time enough to use jquery when somebody else is paying ;)
I am guessing that Chrome freezes its view on the offsetWidth value at the time of the appendChild -- if I uncomment the totally gross hack of styling the image width then it allows the trueContainer to scroll but that also messes with the height with which the thumbnails present in the browser.
Can you suggest anything else ? I cannot claim to be tearing my hair out ( I have none) but I have given this quite a lot of attention
bw
A
2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/cmotiongallery.htm
3) Describe problem: Chrome appears to fix trueContainer offsetWidth before loading images.
4) Sample Site (use Chrome ) : http://aldobranti.eu/#!photography/beaches/P9260355
JScheuer, I have used your cmotion library a number of times and it has given me many opportunities to learn more about JS. Thank you.
I have been working on a do-it-yourself content management system where I get the server side to tell me about image files in a directory and then I populate one of your cmotion controls with a rolling display of thumbnails. The xhr sends returns to the client with a pile of javascript declarations with which I build the contents of trueContainer; here is my xhr call
function galleryRequest(dir,fil,failure) {
"use strict";
var request2= makeHttpObject();
var Y = document.getElementById("trueContainer");
while (Y.childNodes.length){ Y.removeChild(Y.firstChild) };
request2.open("GET","./imageGallery2.php?path="+dir+"/"+fil,true);
request2.send(null);
var myHandler = new Event();
myHandler.addHandler(fillup);
request2.onreadystatechange
= function(){
if(request2.readyState == 4){
if(request2.status == 200) {
gallery = new Array();
//Y.innerHTML = request2.responseText;
doScripts( request2.responseText); // evals the returned JS into an array gallery of objects if ( gallery.length ) {
var frag = document.createDocumentFragment();
for (var g=0;g<gallery.length;g++){
var a = document.createElement('a');
a.href = gallery[ g].href;
var i = document.createElement('img');
i.src = gallery[ g].src;
i.alt = gallery[ g].alt;
i.title = gallery[ g].alt; // i.style.width='48px'; /* totally gross hack */
a.appendChild( i);
frag.appendChild( a);
}
Y.appendChild( frag);
}
myHandler.execute();
} else if (failure) failure(request2.status, request2.statusText)
}
};
}
This works well in FF Safari IE8 and Opera but not in Chrome.
From what I can see trueContainer.offsetWidth (Chrome ) is reporting values like 10 and 20 which seem closer to the accumulated padding of the images while the other browsers report the accumulated image widths.
From the code you'll see that I have picked up on suggestions made to people reporting similar problems in ajax :
• I tried your OO cmotion but it didn't fix Chrome's view of offsetWidth
• I don't use innerHTML
• I use a document fragment to save hitting the DOM
• I use an event to call 'fillup' so that the DOM can redraw before I query offsetWidth
• not shown but have tried a span rather than the nobr
• I don't use jquery because I really want to learn raw JS ( time enough to use jquery when somebody else is paying ;)
I am guessing that Chrome freezes its view on the offsetWidth value at the time of the appendChild -- if I uncomment the totally gross hack of styling the image width then it allows the trueContainer to scroll but that also messes with the height with which the thumbnails present in the browser.
Can you suggest anything else ? I cannot claim to be tearing my hair out ( I have none) but I have given this quite a lot of attention
bw
A