icky_thump
09-08-2008, 08:35 PM
Hi, I'm new here. These types of forums are a lifesaver for a guy like me who still has tons to learn, so thanks to all you zen masters out there. I don't know JS much YET, I can only write simple code and edit it a bit but this one has me stumped. Any pointers are greatly appreciated.
So, I have this Suckerfish HoverLightbox open source code I've downloaded and implemented on my site. Great stuff, works fine. He did a conditional comment for IE6 to point to an external JS file to simulate hover where IE6 didn't understand. Works great.
I have a modification to how it was originally created and that is where things go awry. The original hover was just for text. I want an image to be associated with the text. I have it working everywhere except on that IE6 JS and cannot figure out how to tweak the JS to get it to work.
(The error IE6 gives me is: myTarget.style is null or not an object)
Here is the original HTML:
<div class="gallery" id="gallery1">
<ul>
<li class="first">
<a href="photos/vacation" class="section">
Vacation Photos</a>
</li></ul></div>
Here is my modified HTML:
<div class="gallery" id="gallery1">
<ul>
<li class="first">
<a href="photos/vacation" class="section">
<img src="photos/vacation/vacation1_thumb.jpg" alt="Blue Desert">
<span>Vacation Photos</span>
</a>
</li></ul></div>
(I also tried his orig with my img tag residing before the anchor but same issue)
and here is the original JS:
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
startGallery = function() {
if (document.all && document.getElementById) {
galleries = getElementsByClassName(document, "div", "gallery");
for (x = 0; x < galleries.length; x++) {
galleryRoot = galleries[x].childNodes;
workingID = galleries[x].id;
fullSize = document.getElementById(workingID).firstChild.childNodes.length;
for (i = 0; i < fullSize; i++) {
node = document.getElementById(workingID).firstChild.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
if(this.hasChildNodes()) {
myTarget = this.childNodes[2];
galleryContainer = document.getElementById(workingID);
totalWidth = galleryContainer.offsetWidth;
targetWidth = Math.floor(totalWidth * .94);
myTarget.style.width = targetWidth + 'px';
}
this.className+=" over";
}
node.onmouseout=function() {
this.className = this.className.replace(" over", "");
}
}
}
}
}
}
Event.observe(window, 'load', startGallery, false);
So, I have this Suckerfish HoverLightbox open source code I've downloaded and implemented on my site. Great stuff, works fine. He did a conditional comment for IE6 to point to an external JS file to simulate hover where IE6 didn't understand. Works great.
I have a modification to how it was originally created and that is where things go awry. The original hover was just for text. I want an image to be associated with the text. I have it working everywhere except on that IE6 JS and cannot figure out how to tweak the JS to get it to work.
(The error IE6 gives me is: myTarget.style is null or not an object)
Here is the original HTML:
<div class="gallery" id="gallery1">
<ul>
<li class="first">
<a href="photos/vacation" class="section">
Vacation Photos</a>
</li></ul></div>
Here is my modified HTML:
<div class="gallery" id="gallery1">
<ul>
<li class="first">
<a href="photos/vacation" class="section">
<img src="photos/vacation/vacation1_thumb.jpg" alt="Blue Desert">
<span>Vacation Photos</span>
</a>
</li></ul></div>
(I also tried his orig with my img tag residing before the anchor but same issue)
and here is the original JS:
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
startGallery = function() {
if (document.all && document.getElementById) {
galleries = getElementsByClassName(document, "div", "gallery");
for (x = 0; x < galleries.length; x++) {
galleryRoot = galleries[x].childNodes;
workingID = galleries[x].id;
fullSize = document.getElementById(workingID).firstChild.childNodes.length;
for (i = 0; i < fullSize; i++) {
node = document.getElementById(workingID).firstChild.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
if(this.hasChildNodes()) {
myTarget = this.childNodes[2];
galleryContainer = document.getElementById(workingID);
totalWidth = galleryContainer.offsetWidth;
targetWidth = Math.floor(totalWidth * .94);
myTarget.style.width = targetWidth + 'px';
}
this.className+=" over";
}
node.onmouseout=function() {
this.className = this.className.replace(" over", "");
}
}
}
}
}
}
Event.observe(window, 'load', startGallery, false);