JS。图片上传预览,兼容FF
来源:互联网 发布:电视软件安装 编辑:程序博客网 时间:2024/05/21 09:51
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>imagePreview.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="http://ayue05.blog.163.com/blog/./styles.css">-->
<script type="text/javascript" src="http://ayue05.blog.163.com/blog/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://ayue05.blog.163.com/blog/imagePreview.js"></script>
<script type="text/javascript">
function preview(file,preview,imghead){
if($.browser.msie){
//参数 是否是IE,div的id,img的id,高,宽
previewImage(true,file,preview,imghead,300,400);
}else{
//参数 是否是IE,div的id,img的id,高,宽
previewImage(false,file,preview,imghead,300,400);
}
}
</script>
</head>
<body>
<table>
<tr>
<td>添加圖片:</td>
<td><input type="file" id="file" name="tip.uploadImage" value="文档上传" onchange="preview(this,'preview','imghead')"/>
<div>請上傳 202 pixel X 111 pixel 大小的圖片 </div>
<div id="imagePreview" >图片预览
<div id="preview">
<img id="imghead" width=202 height=111 border=0 />
</div>
</div>
</tr>
</table>
</body>
</html>
IMGJS
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
var param = {top:0, left:0, width:width, height:height};
if( width>maxWidth || height>maxHeight )
{
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if( rateWidth > rateHeight )
{
param.width = maxWidth;
param.height = Math.round(height / rateWidth);
}else
{
param.width = Math.round(width / rateHeight);
param.height = maxHeight;
}
}
param.left = Math.round((maxWidth - param.width) / 2);
param.top = Math.round((maxHeight - param.height) / 2);
return param;
}
function previewImage(isIE,file,preview,imghead,width,height)
{
var MAXWIDTH = width;
var MAXHEIGHT = height;
var div = document.getElementById(preview);
if(isIE){
//IE预览使用滤镜??
// var docObj=document.getElementById(file);
var imgObjPreview=document.getElementById(imghead);
file.select();
// docObj.blur();
var imgSrc = document.selection.createRange().text;
var localImagId = document.getElementById(preview);
//必须设置高宽?
localImagId.style.width = width+"px";
localImagId.style.height = height+"px";
// //????????????????????????é???????¨??·??????????????????é? ??????
localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
imgObjPreview.style.display = 'none';
document.selection.empty();
}else if (file.files && file.files[0])
{
//其他浏览器
div.innerHTML = '<img id='+imghead+'>';
var img = document.getElementById(imghead);
img.onload = function(){
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
img.width = width;
img.height = height;
}
var reader = new FileReader();
reader.onload = function(evt){img.src = evt.target.result;}
reader.readAsDataURL(file.files[0]);
}
else
{
var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="http://ayue05.blog.163.com/blog/';
file.select();
var src = document.selection.createRange().text;
div.innerHTML = '<img id='+imghead+'>';
var img = document.getElementById(imghead);
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
div.innerHTML = "<div id=\"divhead\" style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";
}
}
IMGJS
jquery-1.7.2.min.js
jquery-1.7.2.min.js
<html>
<head>
<title>imagePreview.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="http://ayue05.blog.163.com/blog/./styles.css">-->
<script type="text/javascript" src="http://ayue05.blog.163.com/blog/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://ayue05.blog.163.com/blog/imagePreview.js"></script>
<script type="text/javascript">
function preview(file,preview,imghead){
if($.browser.msie){
//参数 是否是IE,div的id,img的id,高,宽
previewImage(true,file,preview,imghead,300,400);
}else{
//参数 是否是IE,div的id,img的id,高,宽
previewImage(false,file,preview,imghead,300,400);
}
}
</script>
</head>
<body>
<table>
<tr>
<td>添加圖片:</td>
<td><input type="file" id="file" name="tip.uploadImage" value="文档上传" onchange="preview(this,'preview','imghead')"/>
<div>請上傳 202 pixel X 111 pixel 大小的圖片 </div>
<div id="imagePreview" >图片预览
<div id="preview">
<img id="imghead" width=202 height=111 border=0 />
</div>
</div>
</tr>
</table>
</body>
</html>
IMGJS
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
var param = {top:0, left:0, width:width, height:height};
if( width>maxWidth || height>maxHeight )
{
rateWidth = width / maxWidth;
rateHeight = height / maxHeight;
if( rateWidth > rateHeight )
{
param.width = maxWidth;
param.height = Math.round(height / rateWidth);
}else
{
param.width = Math.round(width / rateHeight);
param.height = maxHeight;
}
}
param.left = Math.round((maxWidth - param.width) / 2);
param.top = Math.round((maxHeight - param.height) / 2);
return param;
}
function previewImage(isIE,file,preview,imghead,width,height)
{
var MAXWIDTH = width;
var MAXHEIGHT = height;
var div = document.getElementById(preview);
if(isIE){
//IE预览使用滤镜??
// var docObj=document.getElementById(file);
var imgObjPreview=document.getElementById(imghead);
file.select();
// docObj.blur();
var imgSrc = document.selection.createRange().text;
var localImagId = document.getElementById(preview);
//必须设置高宽?
localImagId.style.width = width+"px";
localImagId.style.height = height+"px";
// //????????????????????????é???????¨??·??????????????????é? ??????
localImagId.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
localImagId.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
imgObjPreview.style.display = 'none';
document.selection.empty();
}else if (file.files && file.files[0])
{
//其他浏览器
div.innerHTML = '<img id='+imghead+'>';
var img = document.getElementById(imghead);
img.onload = function(){
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
img.width = width;
img.height = height;
}
var reader = new FileReader();
reader.onload = function(evt){img.src = evt.target.result;}
reader.readAsDataURL(file.files[0]);
}
else
{
var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="http://ayue05.blog.163.com/blog/';
file.select();
var src = document.selection.createRange().text;
div.innerHTML = '<img id='+imghead+'>';
var img = document.getElementById(imghead);
img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
div.innerHTML = "<div id=\"divhead\" style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;margin-left:"+rect.left+"px;"+sFilter+src+"\"'></div>";
}
}
IMGJS
jquery-1.7.2.min.js
jquery-1.7.2.min.js
0 0
- JS。图片上传预览,兼容FF
- 兼容IE、FF的图片上传预览
- 上传图片预览 兼容IE和FF
- 图片上传前预览(兼容FF和IE)
- 图片上传预览 兼容ie67 8 9 及 FF
- js图片上传预览功能兼容实现
- js图片上传预览兼容IE
- 同时兼容IE和FF的图片上传判断及预览脚本
- JavaScript实现本地图片上传预览功能(兼容IE、chrome、FF)
- 图片上传预览 兼容 IE 6 7 8 9 FF chrome opera等版本
- 最近项目中用到的图片上传前预览功能,兼容IE6-9,FF
- 兼容浏览器图片上传本地预览功能js脚本
- 兼容好的JS图片上传预览代码
- IE兼容上传图片预览
- 上传图片预览,兼容IE8
- ff,ie6,ie7,ie8上传图片预览
- js上传预览 兼容全部
- JS预览上传图片
- FCK 实现Ctrl+Enter提交
- Fckeditor的配置及使用(全)
- JS获取FckEditor的值 FCK
- 嵌套 iframe 取值
- showModalDialog 传值及刷新。弹出子页面,回传给父页面
- JS。图片上传预览,兼容FF
- 在线聊天.NET源码 即时
- JS过虑HTML
- 让DIV的滚动条自动滚动到最底部 - 4种方法(第二种好用)
- js关闭当前页面的几种方式
- jQuery实现AJAX定时局部页面刷新
- 设为首页,收藏本站
- Js 实现页面跳转的几种方式
- js Javascript刷新页面的几种方法