兼容:ie6+,FF,chrome等
示例图:
CSS:
    说明:图像比例为110:135
    下载包里有
jquery.Jcrop.css
    
    .jc-demo-box{position:
relative; background-color: #e7e7e7; width: 395px; height: 340px;
overflow: hidden; border: 1px solid #c8c8c8;}
    #target{max-width:
395px; max-height: 340px;}
    .pre-1,.pre-2,.pre-3{
border: 1px solid #c8c8c8;}
    .pre-1{ width: 110px;
height: 135px; overflow:hidden; }
    .pre-2{ width: 73px;
height: 90px; overflow:hidden; margin-top: 13px; }
    .pre-3{ width: 40px;
height: 48px; overflow:hidden;margin-top: 13px; }
   
.jcrop-holder{overflow:hidden;}
html:
  
 

       
   

  
JS:
$(function(){
 
    var _Jw = ($('#target').width() - 110) / 2 ,
        _Jh = ($('#target').height() - 135) / 2 ,
        _Jw2 = _Jw + 110,
        _Jh2 = _Jh + 135;
    if($("#target").length >= 1){
        var api = $.Jcrop("#target",{
            onChange: showPreview,
            onSelect: showPreview,
            bgFade: true,
            bgOpacity: .5,
            setSelect: [_Jw, _Jh, _Jw2, _Jh2]
        });
    }
    function showPreview(c){
        var iw = $('.jcrop-holder>img').width(),
            ih = $('.jcrop-holder>img').height(),
            rx = 110 / c.w,
            ry = 135 / c.h,
            rx1 = 73 / c.w,
            ry1 = 90 / c.h,
            rx2 = 40 / c.w,
            ry2 = 48 / c.h,
            _data = $(".jc-demo-box").attr("data");
        if($.browser.msie && (_data == 90 || _data == 270)){
                pre_img2($('.pre-1 img'), rx, ih, ry, iw, c.x, c.y);
                pre_img2($('.pre-2 img'), rx1, ih, ry1, iw, c.x, c.y);
                pre_img2($('.pre-3 img'), rx2, ih, ry2, iw, c.x, c.y);
        }else{
            pre_img2($('.pre-1 img'), rx, iw, ry, ih, c.x, c.y);
            pre_img2($('.pre-2 img'), rx1, iw, ry1, ih, c.x, c.y);
            pre_img2($('.pre-3 img'), rx2, iw, ry2, ih, c.x, c.y);
        }
 
    }
    
    $("#idLeft").click(function(e){
        imgRotate(-90);
        stopEvent(e);
    });
    $("#idRight").click(function(e){
        imgRotate(90);
        stopEvent(e);
    });
    $("#idBig").click(function(e){
        imgToSize(20);
        stopEvent(e);
    });
    $("#idSmall").click(function(e){
        imgToSize(-20);
        stopEvent(e);
    });
});
//图片旋转
var imgRotate = function(deg){
    var img1 = $(".jcrop-holder>img"),
        img2 = $("#real"),
        _data = parseInt($(".jc-demo-box").attr("data"));
    if($.browser.msie){
        var sin = Math.sin(Math.PI / 180 * (_data + deg));
        var cos = Math.cos(Math.PI / 180 * (_data + deg));
        var _filter = "progid:DXImageTransform.Microsoft.Matrix(M11=" + cos + "," +  "M12=" + (-sin)
            + ",M21=" + sin+ ",M22=" + cos + ",SizingMethod='auto expand')";
        img1.css({
            filter: _filter + "alpha(opacity=60)",
            opacity: 0.6
        });
        img2.css({
            filter: _filter
        });
        $('.pre-1 img,.pre-2 img,.pre-3 img').css({
            filter: _filter
        });
        var _w = img1.width(),
            _h = img1.height();
        $('.jcrop-holder').width(_w).height(_h).css({
            left: Math.round((395 - _w) / 2) + 'px',
            top: Math.round((340 - _h) / 2) + 'px'
        });
    }else{
        var _deg = deg + _data;
        var _val =  "rotate("+ _deg + "deg)";
        img1.css({
            "-webkit-transform": _val,
               "-moz-transform": _val,
                "-ms-transform": _val,
                 "-o-transform": _val,
                    "transform": _val
        });
        img2.css({
            "-webkit-transform": _val,
               "-moz-transform": _val,
                "-ms-transform": _val,
                 "-o-transform": _val,
                    "transform": _val
        });
        $('.pre-1 img,.pre-2 img,.pre-3 img').css({
            "-webkit-transform": _val,
               "-moz-transform": _val,
                "-ms-transform": _val,
                 "-o-transform": _val,
                    "transform": _val
        });
    }
    if( deg > 0){
        if(_data == 270){
            _data = 0;
        }else{
            _data = _data + 90;
        }
    }else{
        if(_data == 0){
            _data = 270;
        }else{
            _data = _data - 90;
        }
    }
    $(".jc-demo-box").attr("data", _data);
}
 
//放大缩小图片
var imgToSize = function (size) {
        var img1 = $(".jcrop-holder>img"),
            img2 = $("#real"),
            ow=img1.width(),
            oh=img1.height(),
            rx = $("#small").width(),
            ry = $("#small").height(),
            cx = $("#small").position().left,
            cy = $("#small").position().top,
            _w = Math.round(ow + size),
            _h = Math.round(((ow + size) * oh) / ow),
            _data = $(".jc-demo-box").attr("data");
        $('.jcrop-holder').width(_w).height(_h).css({
            left: Math.round((395 - _w) / 2) + 'px',
            top: Math.round((340 - _h) / 2) + 'px'
        });
    if($.browser.msie && (_data == 90 || _data == 270)){
            img1.width(_h).height(_w);
            img2.width(_h).height(_w);
            pre_img($('.pre-1 img'), rx, oh, ry, ow, cx, cy, 110, 135);
            pre_img($('.pre-2 img'), rx, oh, ry, ow, cx, cy, 73, 90);
            pre_img($('.pre-3 img'), rx, oh, ry, ow, cx, cy, 40, 48);
    }else{
        img1.width(_w).height(_h);
        img2.width(_w).height(_h);
        pre_img($('.pre-1 img'), rx, ow, ry, oh, cx, cy, 110, 135);
        pre_img($('.pre-2 img'), rx, ow, ry, oh, cx, cy, 73, 90);
        pre_img($('.pre-3 img'), rx, ow, ry, oh, cx, cy, 40, 48);
    }
 
}
var pre_img2 = function(obj, rx, iw, ry, ih, cx, cy){
    obj.css({
        width: Math.round(rx * iw) + 'px',
        height: Math.round(ry * ih) + 'px',
        marginLeft: '-' + Math.round(rx * cx) + 'px',
        marginTop: '-' + Math.round(ry * cy) + 'px'
    });
}
var pre_img = function(obj, rx, ow, ry, oh, cx, cy, w, h){
    obj.css({
        width: Math.round( w / rx * ow) + 'px',
        height: Math.round(h / ry * oh) + 'px',
        marginLeft: '-' + Math.round(w / rx * cx) + 'px',
        marginTop: '-' + Math.round(h / rx * cy) + 'px'
    });
}
 
 
 

jQuery 上传头像插件Jcrop的实例的更多相关文章

  1. jQuery 自制上传头像插件-附带Demo实例(ajaxfileupload.js第三弹)

    这篇文章主要是对前两篇关于ajaxfileupload.js插件的文章 <ASP.NET 使用ajaxfileupload.js插件出现上传较大文件失败的解决方法(ajaxfileupload. ...

  2. JQuery上传文件插件Uploadify使用笔记

    新工作的第一份任务就是给实现 限制Uploadify 上传文件格式为图片 测试出来报错,选择了非图片文件,提示错误后,再选择其他文件,上传时还是包含了之前清空的非图片文件 最后实现效果的代码是 //上 ...

  3. JQuery 上传文件插件 Uploadify1

    基于jquery的文件上传控件,支持ajax无刷新上传,多个文件同时上传,上传进行进度显示,删除已上传文件. <link href="~/Content/themes/uploadif ...

  4. 上传文件插件dropzone的实例

    html: <div class="field"> <div id="file" class="dropzone"> ...

  5. jquery头像上传剪裁插件cropper的前后台demo

    因为一个项目要做一个头像上传的功能,因此选择了使用jquery的头像插件cropper,cropper是一款使用简单且功能强大的图片剪裁jQuery插件,但是在使用的时候,有一个很大的坑需要注意,那就 ...

  6. Jcrop+uploadify+php实现上传头像预览裁剪

    最近由于项目需要,所以做了一个上传头像预览并且可以预览裁剪的功能,大概思路是上传的图片先保存到服务器,然后通过ajax从服务器获取到图片信息,再利用Jcrop插件进行裁剪,之后通过PHP获取到的四个裁 ...

  7. 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据

    1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...

  8. jQuery上传插件,文件上传测试用例

    jQuery上传插件,文件上传测试用例 jQuery File Upload-jQuery上传插件介绍http://www.jq22.com/jquery-info230 jQuery File Up ...

  9. JQuery上传插件uploadify优化

    旧版的uploadify是基于flash上传的,但是总有那么些问题,让我们用的不是很舒服.今天主要分享下在项目中用uploadify遇到的一些问题,以及优化处理 官方下载 官方文档 官方演示 下面是官 ...

随机推荐

  1. K-近邻算法(KNN)

    简介 k近邻算法是数据分类一种常用的算法,属于监督学习算法的一类,它采用不同特征值之的距离进行分类.K近邻算法具有精度高.对异常值不敏感.无数据输入假定的优点,缺点是计算复杂度高.空间复杂度高.适用于 ...

  2. AngularJS 第三天----作用域

    作用域的概念及其功能 AngularJS使用作用域的概念来充当数据模型的作用,在视图和控制器之间起着桥梁的作用.由于双向绑定的数据特性,视图的修改会更新 $scope,同样对 $scope的修改也会重 ...

  3. BCL中String.Join的实现

    在开发中,有时候会遇到需要把一个List对象中的某个字段用一个分隔符拼成一个字符串的情况.比如在SQL语句的in条件中,我们通常需要把List<int>这样的对象转换为“1,2,3”这样的 ...

  4. [Solr] (源) Solr与MongoDB集成,实时增量索引

    一. 概述 大量的数据存储在MongoDB上,需要快速搜索出目标内容,于是搭建Solr服务. 另外一点,用Solr索引数据后,可以把数据用在不同的项目当中,直接向Solr服务发送请求,返回xml.js ...

  5. 【WCF】为终结点地址应用地址头

    记得不久前,老周写过博文,探讨过在ContextScope以一定的范内向发出的消息中插入消息头,scope只能为特定的某一次服务操作的调用而添加SOAP头,要是需要在每次调用操作协定的时候都插上Hea ...

  6. CRL快速开发框架系列教程二(基于Lambda表达式查询)

    本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...

  7. SharePoint 2103 Check user permission on list

    一.需求: check user 对SharePoint list 的permission 代码如下: private static string GetListPermission(SPList l ...

  8. 【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 特殊问题和实战经验(五)

    RAC 特殊问题和实战经验(五) 概述:写下本文档的初衷和动力,来源于上篇的<oracle基本操作手册>.oracle基本操作手册是作者研一假期对oracle基础知识学习的汇总.然后形成体 ...

  9. Oracle基础维护02-表、主键、索引、表结构维护手册

    目录 一.项目新建表.主键.索引注意事项 二.举例说明建表.主建.索引的操作方法 2.1 设定需求如下 2.1.1 查询数据库有哪些表空间 2.1.2 本文档假设数据库有这两个业务用户的表空间 2.2 ...

  10. Scrapy:为spider指定pipeline

    当一个Scrapy项目中有多个spider去爬取多个网站时,往往需要多个pipeline,这时就需要为每个spider指定其对应的pipeline. [通过程序来运行spider],可以通过修改配置s ...