【发布时间】:2010-02-10 18:40:00
【问题描述】:
我正在尝试使用 CSS 创建一个“舷窗”。当我说舷窗时,我的意思是让屏幕的一部分透视,这样你就可以看到舷窗后面的任何东西。
通过将主体的背景颜色设置为与前景色相同,然后使用具有圆形渐变的舷窗图像,我能够获得我想要的效果,中间为白色,边缘为黑色因为页面上的所有内容都是相同的颜色。这不是我想要的,因为我想在屏幕后面使用颜色或任何东西。
我想出了这个:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test See Through Mouse</title>
<script type="text/javascript" src="jquery-1.4.1.js"></script>
<style type="text/css">
* { margin: 0; padding: 0; }
html, body { height: 100%; background-color: green; }
#cover { height: 100%; width: 100%; top: 0; position: fixed; background: url(porthole.png) no-repeat; }
</style>
</head>
<body>
Hi, I am behind the scenes content. Hi, I am behind the scenes content. Hi, I am behind the scenes content.
<!-- repeated enough times to fill the screen with text -->
<div id="cover"></div>
<script type="text/javascript">
$('#cover').live('mousemove', function(e) {
<!-- the image is 3000px by 3000px and I want the center of the visible part where the mouse is -->
$('#cover').css('background-position', (e.pageX - 1500) + 'px ' + (e.pageY - 1500) + 'px');
});
</script>
</body>
</html>
其中舷窗图像是一个巨大的 PNG 图像(在每个方向上都是我的屏幕大小的数倍),中间有一个不可见的小圆圈(约 200 像素 x 200 像素)。这确实给出了我想要的效果,但主要问题是我不知道用户的屏幕尺寸,但我也不想使用对用户来说太大的图像,因为移动它会明显变得不稳定随着图像大小的增长。
有没有办法让我只需要提供一个与实际舷窗图形大小相同的舷窗图像,而使用其他方法来掩盖屏幕的其余部分?我愿意只使用 HTML(5 即可)、CSS 和 javascript。
【问题讨论】:
-
嘿嘿嘿——这在flash的早期曾经风靡一时
标签: javascript html css