网页鼠标滚动实现图片缩放
2010-03-25 18:30
387 查看
<SCRIPT LANGUAGE="JavaScript">
<!--
//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight) {
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
ImgD.style.cursor= "pointer"; //改变鼠标指针
ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
ImgD.title = "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
ImgD. = function img_zoom() //滚轮缩放
{
var zoom = parseInt(this.style.zoom, 10) || 100;
zoom += event.wheelDelta / 12;
if (zoom> 0) this.style.zoom = zoom + "%";
return false;
}
} else { //如果不是IE
ImgD.title = "点击图片可在新窗口打开";
}
}
}
//-->
</SCRIPT>
<style type=css>
</style>
<div class="test">
<img name="" src="123.jpg" onload="javascript:resizeimg(this,198,235)">
<div>
<!--
//图片按比例缩放,可输入参数设定初始大小
function resizeimg(ImgD,iwidth,iheight) {
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
ImgD.style.cursor= "pointer"; //改变鼠标指针
ImgD.onclick = function() { window.open(this.src);} //点击打开大图片
if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判断浏览器,如果是IE
ImgD.title = "请使用鼠标滚轮缩放图片,点击图片可在新窗口打开";
ImgD. = function img_zoom() //滚轮缩放
{
var zoom = parseInt(this.style.zoom, 10) || 100;
zoom += event.wheelDelta / 12;
if (zoom> 0) this.style.zoom = zoom + "%";
return false;
}
} else { //如果不是IE
ImgD.title = "点击图片可在新窗口打开";
}
}
}
//-->
</SCRIPT>
<style type=css>
</style>
<div class="test">
<img name="" src="123.jpg" onload="javascript:resizeimg(this,198,235)">
<div>
相关文章推荐
- C#实现图片鼠标拖动和滚动缩放
- C#实现图片鼠标拖动和滚动缩放
- 用 JavaScript 实现网页图片等比例缩放
- 网页随鼠标滚动自动加载 之 网页缩放后失效问题解决方法
- 实现图片滑动、滚动、菜单栏(导航)滑动、文字滚动等效果的网页插件superslide2
- wpf图片查看器,支持鼠标滚动缩放拖拽
- jQuery实现滚动鼠标放大缩小图片的方法(附demo源码下载)
- MFC GDI+实现以鼠标为中心缩放图片(并且可以拖动)
- js实现鼠标滚轮控制图片缩放效果的方法(转)
- 鼠标滚轮实现图片的缩放-------Day79
- js实现鼠标滚轮控制图片缩放效果的方法
- 用 JavaScript 实现网页图片等比例缩放
- 利用鼠标滚轮实现图片缩放
- jQuery实现滚动鼠标放大缩小图片的方法(附demo源码下载)
- 在WPF里面实现以鼠标位置为中心缩放移动图片
- CSS实现网页图片的等比例缩放
- 用roll.js实现的图片自动滚动+鼠标触动的特效
- javascript 实现网页图片等比例缩放
- ZK集成jqueryui 实现图片鼠标滚轮缩放以及拖拽位置