Now, the rollover sort of works exactly the way I want it to (I want to show a red X over top of the main image. The image is read from the directory, modified using GD to a thumbnail size and then displayed so the sizes may vary depending on the original.
However, the link disappears and I cannot click on the link. I eventually want it so I can delete the image by clicking on it. How can I get my link back YET keep the hover image?
Also, on a side note there is about 1-2 pixels at the bottom of every image that if landed on just right creates another overlay over the first overlay giving it two overlays on one image. How would I fix that as well. Thanks.
#1: You can’t have the same ID more than once in a document. Instead, make it a class.
#2: Divs are block-level elements and are technically not allowed in anchors. Although it doesn’t matter here validation wise it could have a different outcome in different browsers. Instead, use a span or something, or at least make your anchors display as block-level elements, too.
#3: Don’t mix JS and CSS (unless you need to get or set values dynamically). Instead, apply a class (if necessary at all) to the newly appended element and style it with CSS then.
I didn’t say “Make the elements named ‘special’ a span”, they can stay a div.
But anyway, this happens when I don’t test code that I propose. I realize now that the “this” keyword doesn’t work since it’s not within a function. You’d have to change it to:
It seems to be working correctly now (only after the page is completed loading but I can work on that part). However, it only reads the width and height from the first image. Not all of the images are the same size so I get some with the overlay not covering the whole image. (I've included and example)
Ah dammit! Yeah, these are things I find out myself step by step when I’m sitting over such a task. Of course my last version wouldn’t work like that. As I mentioned earlier in this case you’ll have to use an each() loop. Try this:
That seems to have it working... just a few small bugs to work out.
#1: I stated this one earlier and I cannot see why it is doing this. When the page first loads there is a little red square that shows instead of the default red x. If I refresh the page in my browser it works as it should (with exception of #2).
#2: The taller photos has their overlay over to the left. I currently have the image centered in the cell. The overlay is left justified and I cannot manage to move it over using any of my CSS tricks.
For the first one it would help to see the page itself. The second one is because the anchors are set to display as block elements, and hence, they are filling the entire width of each cell. The appended span elements are positioned absolutely at the top left of the anchor while the images are centered; that’s why. You’ll have to position the spans left: 50% and margin-left by half of their width (do that with JS) to center them, too.
Oh, I get it. The problem is that the images take some time to load and since they have no specific dimensions set in the HTML (or CSS) the script calculates the image dimensions before they are actually loaded, hence getting them wrong and therefore setting the span’s dimensions wrong, too. Properly calculating image dimensions has always been a problem in one or another browser, I’ve found that the safest way is to set the width and height attributes of the image elements so they have specific dimensions right from the beginning for JS to pick that up. The reason why it’s red is because the X is right in the middle and that’s what you see of the X when the container is so small.
And the margin must be negative, by the way. Sorry if I forgot to mention this.