动态改变图片尺寸(二)

来源:互联网 发布:淘宝后whoo小样真假 编辑:程序博客网 时间:2024/06/05 10:19
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
下面我给出了整个函数的原代码:// sizeTo() 改变图片尺寸函数(跨浏览器)function sizeTo(layerName, img, iHeight, iWidth, animate) {var ie4 = (document.all)if (ie4) {var targetLayer = document.all[layerName]// 定位要改变大小的图片var el = targetLayer.children.tags("IMG")[0]// 加入一个标识。el.clip = new Object }else {//现在还不能改变图片的大小//因为在Netscape中要通过操纵DIV来改变图片大小 var el = document.layers[layerName]//再加上一个CSS属性el.style = new Object// 存储当前在IE中的高和宽值。el.style.pixelHeight = el.offsetHeight = el.clip.height el.style.pixelWidth = el.offsetWidth = el.clip.width}if (!animate) { //如果不要改变的动画,就直接改变图片的大小if (ie4) { //在IE中直接改变图片的长宽el.style.pixelWidth = iWidth; el.style.pixelHeight = iHeight}else {// 在Netscape中的处理方法el.document.write(""); el.document.close(); }}elseif ((el.offsetHeight != iHeight) || (el.offsetWidth != iWidth)) {//注意这里的语句,这是在不同浏览器中有相同效果的关键if (el.offsetHeight < iHeight) el.style.pixelHeight = el.clip.height = el.offsetHeight + 1;if (el.offsetWidth < iWidth) el.style.pixelWidth = el.clip.width = el.offsetWidth + 1;if (el.offsetHeight > iHeight) el.style.pixelHeight = el.clip.height = el.offsetHeight - 1;if (el.offsetWidth > iWidth) el.style.pixelWidth = el.clip.width = el.offsetWidth - 1;if (!ie4) {el.document.write("");el.document.close();}//继续动画效果setTimeout("sizeTo("" + layerName + "",""+img+"","+iHeight+","+iWidth+","+animate+")",10);} }好了,让我们来看一下演示吧  好了,这就是所有我想说的。不过最后,我想说的是,通过这个例子,我旨在说明IE和Netscape中的不同点,也是在提醒各位,你的动态HTML要跨浏览器是很不容易的,而且要做到这点,你必须要搞清楚这两种浏览器中的一些设置。 <script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>