无标题文章

$(".photo img").attr("src", src);
$(".preview img").attr("src", src);
$('.photo img').imgAreaSelect({
x1: 0,
y1: 0,
x2: 80,
y2: 80, selectionOpacity: 0.2, aspectRatio: '1:1', onSelectChange: preview, zIndex: 10000, persistent: true
});
$("#edit-photo .lj-btn").attr({ "scale": "1", "x1": "0", "y1": "0", "x2": "80", "y2": "80" });

                    $(".edit_photo").click();
                    justOnece = true;






    //图片选区
    function preview(img, selection) {
        var scaleX = 80 / (selection.width || 1);
        var scaleY = 80 / (selection.height || 1);

        $('.preview img').css({
            width: Math.round(scaleX * $(img).width()) + 'px',
            height: Math.round(scaleY * $(img).height()) + 'px',
            marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px',
            marginTop: '-' + Math.round(scaleY * selection.y1) + 'px'
        });
        $("#edit-photo .lj-btn").attr({ "scale": scaleX, "x1": selection.x1, "y1": selection.y1, "x2": selection.x2, "y2": selection.y2 });
    }

    //确定所选区域
    function avatarResize() {
        var obj = $("#edit-photo .lj-btn");
        //需裁剪的头像 和 当前头像
        var src = $(".photo img").attr("src");
        var oldsrc = $("img.v-align-middle").attr("src");

        if (src.indexOf("http://") > -1) {
            src = src.substring(src.indexOf("/Files"));
        }
        var dataToSend = { src: src, x1: obj.attr('x1'), y1: obj.attr('y1'), x2: obj.attr('x2'), y2: obj.attr('y2') };
        $.ajax({
            url: "/User/PhotoResize",
            data: dataToSend,
            dataType: "json",
            type: "POST",
            success: function (res) {
                if (res.Suc) {
                    $("img.v-align-middle,#loginuser img").attr("src", res.Msg);
                    $("#edit-photo").colorbox.close();
                }
                else
                    sf.sf_Message(res.Msg, 2);
            },
            error: function (data, status, e) {
                sf.sf_Message("修改图片大小失败:" + e, 2);
            },
            complete: function (data, status) {
                $(".mugshot-container").removeClass("loading");
                $(".mugshot-container img").css("visibility", "visible");
            }
        });
    }

你可能感兴趣的:(无标题文章)