鼠标越接近图像,图像会越大,它会很聪明的判断出图像中心距鼠标的距离
2006-06-08 13:19
399 查看
[align=center]以下代码加入<head>区域[/align]
[align=left] [/align]
<script language="javascript">
<!--
//more javascript from http://www.smallrain.net
document.onmousemove = beSmart;
window.onload = init;
startEnlarge = 250; // The distance to start enlarging the picture at, in pixels.
enlargeTo = 200; // The number of Pixels to enlarge to.
minSize = 40; // The number of Pixels to shrink to.
centerOfPic = new Array();
// Calls the beSmart function to set each "smart" image to the correct size.
function init(){
beSmart();
}
function beSmart(){
for(i=0;i<document.images.length;i++){
if(document.images[i].className == "smart"){
mouseX = window.event.x;
mouseY = window.event.y;
imageX = document.images[i].offsetLeft + (document.images[i].width / 2);
imageY = document.images[i].offsetTop + (document.images[i].height / 2);
distance = Math.ceil(Math.sqrt(Math.pow(mouseX - imageX,2) + Math.pow(imageY - mouseY,2)));
percent = distance / startEnlarge * enlargeTo;
percent = enlargeTo - percent
if(percent > minSize){
document.images[i].style.width = percent;
document.images[i].style.height = percent;
} else {
document.images[i].style.width = minSize;
document.images[i].style.height = minSize;
}
}
}
}
// -->
</script>
[align=center]以下代码加入<body>区域[/align]
[align=left]<center><img src="jsimg/pic1.jpg" class="smart">
<img src="jsimg/pic2.jpg" class="smart">
<img src="jsimg/pic3.jpg" class="smart">
<img src="jsimg/pic4.jpg" class="smart">
<img src="jsimg/pic5.jpg" class="smart"></center>[/align]
[align=left] [/align]
<script language="javascript">
<!--
//more javascript from http://www.smallrain.net
document.onmousemove = beSmart;
window.onload = init;
startEnlarge = 250; // The distance to start enlarging the picture at, in pixels.
enlargeTo = 200; // The number of Pixels to enlarge to.
minSize = 40; // The number of Pixels to shrink to.
centerOfPic = new Array();
// Calls the beSmart function to set each "smart" image to the correct size.
function init(){
beSmart();
}
function beSmart(){
for(i=0;i<document.images.length;i++){
if(document.images[i].className == "smart"){
mouseX = window.event.x;
mouseY = window.event.y;
imageX = document.images[i].offsetLeft + (document.images[i].width / 2);
imageY = document.images[i].offsetTop + (document.images[i].height / 2);
distance = Math.ceil(Math.sqrt(Math.pow(mouseX - imageX,2) + Math.pow(imageY - mouseY,2)));
percent = distance / startEnlarge * enlargeTo;
percent = enlargeTo - percent
if(percent > minSize){
document.images[i].style.width = percent;
document.images[i].style.height = percent;
} else {
document.images[i].style.width = minSize;
document.images[i].style.height = minSize;
}
}
}
}
// -->
</script>
[align=center]以下代码加入<body>区域[/align]
[align=left]<center><img src="jsimg/pic1.jpg" class="smart">
<img src="jsimg/pic2.jpg" class="smart">
<img src="jsimg/pic3.jpg" class="smart">
<img src="jsimg/pic4.jpg" class="smart">
<img src="jsimg/pic5.jpg" class="smart"></center>[/align]
相关文章推荐
- 对导入的图像,随机用鼠标在图像中取一个点,算这个点到点A、B、C、D四个点距离最小者,返回该最小距离
- 计算鼠标至元素中心的距离
- [C#, WPF] 根据鼠标距离窗口中心的距离设置其背景色
- 类似地图的以鼠标为中心缩放图像
- 用jQuery 判断鼠标滚轮滑动距离?
- 用jQuery 判断鼠标滚轮滑动距离?
- 【Unity】UGUI如何判断鼠标或者手指是否点击到UI上
- C# 判断系统空闲(键盘、鼠标不操作一段时间)
- Android——高德地图设置中心点和缩放比例,获取两点之间距离
- 判断屏幕滚动距离
- 判断鼠标滚动方向
- MFC 以图像大小打开并显示图像,鼠标左击显示像素坐标
- 鼠标经过图像,内容变换
- 懒就要懒到底――鼠标自动点击(含时间判断)
- 向量叉积应用-判断鼠标移动方向
- js判断鼠标滚动放下,向上滚还是向下滚?
- 判断图像是黑白图像
- 关于js拖拽功能,拖拽元素的position:fixed;left:0;right:0;样式引起左右拖动元素会出现落后鼠标移动距离的问题
- C#实现图像的鼠标裁剪
- 判断鼠标移动方向