资源描述
无标题文档Firefox3,IE6,IE7,IE8上传图片预览 #preview_fake /* 该对象用于在IE下显示预览图片 */ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale); #preview_size_fake /* 该对象只用来在IE下获得图片的原始尺寸,无其它用途 */ filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=image); visibility:hidden; function onUploadImgChange(sender) if( !sender.value.match( /.jpg|.gif|.png|.bmp/i ) ) alert(图片格式无效!); return false; var objPreview = document.getElementById( preview ); var objPreviewFake = document.getElementById( preview_fake ); var objPreviewSizeFake = document.getElementById( preview_size_fake ); if( sender.files & sender.files0 ) objPreview.style.display = block; objPreview.style.width = auto; objPreview.style.height = auto; /Firefox 因安全性问题已无法直接通过 inputfile.value 获取完整的文件路径 /支持FF7.0以上版本的写法:window.URL.createObjectUrl(sender.files0); objPreview.src = sender.files0.getAsDataURL(); else if( objPreviewFake.filters ) /IE7, IE8因安全性问题已无法直接通过 inputfile.value 获取完整的文件路径 /IE7,IE8 在设置本地图片地址: img.src 时相同环境有时无法正常显示,因此用滤镜解决此问题。 sender.select(); var imgSrc = document.selection.createRange().text; objPreviewFake.filters.item(DXImageTransform.Microsoft.AlphaImageLoader).src = imgSrc; objPreviewSizeFake.filters.item( DXImageTransform.Microsoft.AlphaImageLoader).src = imgSrc; /alert(objPreviewSizeFake.offsetWidth+-+objPreviewSizeFake.offsetHeight); autoSizePreview( objPreviewFake, objPreviewSizeFake.offsetWidth, objPreviewSizeFake.offsetHeight ); objPreview.style.display = none; function onPreviewLoad(sender) autoSizePreview( sender, sender.offsetWidth, sender.offsetHeight ); function autoSizePreview( objPre, originalWidth, originalHeight ) var zoomParam = clacImgZoomParam( 200, 150, originalWidth, originalHeight ); objPre.style.width = zoomParam.width + px; objPre.style.height = zoomParam.height + px; function clacImgZoomParam( maxWidth, maxHeight, width, height ) var param = width:width, height:height ; if( widthmaxWidth | heightmaxHeight ) rateWidth = width / maxWidth; rateHeight = height / maxHeight; if( rateWidth rateHeight ) param.width = maxWidth; param.height = height / rateWidth; else param.width = width / rateHeight; param.height = maxHeight; return param;
展开阅读全文