I started writing a Greasemonkey script as a start for learning JavaScript. What the script does is simply when you hover your mouse pointer over a thumbnail image, if enlarges that picture to a popup window.
And I'm almost done. But there's a few snags...
when the mouseenter event fires, it spawns a popup and it also loads that same image in the webpage itself! Thus preventing it from executing the mouseleave part too, I think.
How do I set the width and the height of the popup dynamically according to the particular measurements of the loading image?
In the '/thumbs/75x60/' part, I want to use the * wildcard to replace '75x60' (as in * x * ) so that any size of thumbnail pic would be affected. How do I do that?
See http://jsfiddle.net/JWcB7/6/
The HTML is like:
<div id="profPhotos">
<a class="profPhotoLink" href="...">
<img width="95" height="130" src=".../thumbs/163x130/8f/fd/588x800_1319044306_9223981.jpg">
</a>
<br>
<a class="profPhotoLink" href="...">
<img width="75" height="60" src=".../thumbs/75x60/f0/d9/604x453_1319044306_9254715.jpg">
</a>
... ...
</div>
The JS is:
$('#profPhotos .profPhotoLink > img').bind
(
"mouseenter mouseleave", myImageHover
);
function myImageHover (zEvent)
{
if (zEvent.type == 'mouseenter')
{
var imgurl = this.src.toString();
//need to replace '/thumbs/75x60/' part with '/photos/' to get the full size image
var bigimg = imgurl.replace("/thumbs/75x60/", "/photos/");
window.location.href = bigimg;
popup = window.open(bigimg,"popwindow","menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,scrollbars=0,location=0,width=600,height=800") //how to set the width and the height dynamically
}
else
{
popup.close();
}
}