图片加载前修改图片的大小

来源:互联网 发布:淘宝图书许可证怎么办 编辑:程序博客网 时间:2024/04/27 16:37

<script src="../js/jquery.min.js"></script>

<script type="text/javascript">

jQuery(window).load(function () {
 //jQuery(function($){

//按比例放缩图片
  $("img").each(function(){
    if(this.id=='srcImg'){
    var image=this;
    if(image.width>400||image.height>400){
      var w;
     var h; 
     if(image.width>image.height){
      w=400;
      h=400/image.width*image.height;
     }else{
     w=400/image.height*image.width;
     h=400;
     }       
       $('#srcImg').width(w);
       $('#srcImg').height(h);
       //$('#srcImg').css('visibility','visible');
       
    }

     }
      });
});

</javascript>

<img alt="原图" id="srcImg" src="<%=path %>" > 

在使用 //jQuery(function($){});加载图片时在火狐浏览器中会有显示原图片大小的bug,改用jQuery(window).load(function () { });可以解决该问题。

 

原创粉丝点击