js按比例缩放图片并显示图片的一部分

2015-11-25 11:56:03
$(document).ready(function(){  
    //取得图片外层div的宽度  
    var boxwidth = $(‘.media-object’).parent().width();  
    var boxheight = boxwidth*9/16;  
    var imgarray = $(‘.media-object’);  
    for(var i=0;i<imgarray.length;i++){  
        //获取图片原始长、宽  
        var width = imgarray[i].width ;  
        var height = imgarray[i].height;  
        //判断图片长宽比例  
        if( width*9/16 > boxheight ){  
            //使用宽度按16:9的比例缩放后高度不够,转而使用高度  
            //此时图片高度应该设为div高 boxheight  
            var imgheight = boxheight;  
            $(imgarray[i]).css(‘height’,imgheight);  
            //此高度下等比例的图片宽度为 imgwidth  
            var imgwidth = imgheight*width/height;  
            $(imgarray[i]).css(‘width’,imgwidth);  
            //计算此时图片宽度与div宽度的差值  
            var difference = imgwidth-boxwidth;  
            //计算图片应该裁剪的位置  
            var stratX = difference/2;  
            var startY = 0;  
            var endX = imgwidth – difference/2;  
            var endY = imgheight;  
            //使用css clip:rect(top, right, bottom, left)属性裁剪  
            $(imgarray[i]).css(‘clip’,’rect(‘+stratX+’px ‘+endX+’px ‘+endY+’px ‘+startY+’px)’);  
        }else{  
            //使用宽度按照16:9缩放,多余的高度去除  
            //此时图片宽度应该设为div宽 boxwidth  
            var imgwidth = boxwidth;  
            $(imgarray[i]).css(‘width’,imgwidth);  
            //此宽度下等比例的图片高度为 imgheight  
            var imgheight = imgwidth*height/width;  
            $(imgarray[i]).css(‘height’,imgheight);  
            //计算此时图片高度与div高度的差值  
            var difference = imgheight-boxheight;  
            //计算图片应该裁剪的位置  
            var stratX = 0;  
            var startY = difference/2;  
            var endX = imgwidth;  
            var endY = imgheight – difference/2;  
            //使用css clip:rect(top, right, bottom, left)属性裁剪  
            $(imgarray[i]).css(‘clip’,’rect(‘+stratX+’px ‘+endX+’px ‘+endY+’px ‘+startY+’px)’);  
        }  
    }  
}); 
CentOS 升级 Git 至最新版

Centos使用git push代码时报错(The requested URL returned error: 400),环境为centos6、git1.7.1。 Coding文档提示git version低于1.9可能会报错,遂升级git至最新版。 由于CentOS用yum安装的版本只有1.x,故需要手动编译安装。 首先,下载git安装包。 从github上下载一个最新版(撰写文章时的最新版为:2.6.0)。 cd /usr/local/src wget https://github.com/git/git/archive/master.zip unzip master.zip 由于系统中已存在git,所以先备份现有git。 mv /usr/bin/git{,.bak} 编译安装

Brew error: Could not symlink, path is not writable

When I try to link a library with homebrew ( brew link libtool), I got the following error: Linking /usr/local/Cellar/libtool/2.4.6… Error: Could not symlink lib/libltdl.7.dylib /usr/local/lib is not writable. As explained here by Rick: Start with brew doctor which will