【发布时间】:2011-12-09 19:54:05
【问题描述】:
我开始编写 Greasemonkey 脚本作为学习 JavaScript 的开始。脚本所做的只是将鼠标指针悬停在缩略图上,然后将该图片放大到弹出窗口。
我快完成了。但是有一些障碍......
当 mouseenter 事件触发时,它会生成一个弹出窗口,并且它还会在网页本身中加载相同的图像!我认为,因此也阻止了它执行 mouseleave 部分。
如何根据加载图像的特定测量值动态设置弹出窗口的宽度和高度?
在 '/thumbs/75x60/' 部分,我想使用 * 通配符替换 '75x60' (如 * x * ),这样任何大小的缩略图都会受到影响。我该怎么做?
HTML 是这样的:
<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>
JS 是:
$('#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();
}
}
【问题讨论】: