js截图

首先要准备4个js文件:

1)prototype.js

var Class = {
    create: function() {
        return function() { this.initialize.apply(this, arguments); }
    }
}

var Extend = function(destination, source) {
    for (var property in source) {
        destination[property] = source[property];
    }
}

var Bind = function(object, fun) {
    return function() {
        return fun.apply(object, arguments);
    }
}

var BindAsEventListener = function(object, fun) {
    var args = Array.prototype.slice.call(arguments).slice(2);
    return function(event) {
        return fun.apply(object, [event || window.event].concat(args));
    }
}

var CurrentStyle = function(element) {
    return element.currentStyle || document.defaultView.getComputedStyle(element, null);
}

function addEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.addEventListener) {
        oTarget.addEventListener(sEventType, fnHandler, false);
    } else if (oTarget.attachEvent) {
        oTarget.attachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = fnHandler;
    }
};

function removeEventHandler(oTarget, sEventType, fnHandler) {
    if (oTarget.removeEventListener) {
        oTarget.removeEventListener(sEventType, fnHandler, false);
    } else if (oTarget.detachEvent) {
        oTarget.detachEvent("on" + sEventType, fnHandler);
    } else {
        oTarget["on" + sEventType] = null;
    }
};

2)ImgCropper.js

//图片切割
var ImgCropper = Class.create();
ImgCropper.prototype = {
    //容器对象,控制层,图片地址
    initialize: function(container, handle, url, options) {
        this._Container = $(container); //容器对象
        this._layHandle = $(handle); //控制层
        this.Url = url; //图片地址

        this._layBase = this._Container.a(document_createElement_x_x_x("img")); //底层
        this._layCropper = this._Container.a(document_createElement_x_x_x("img")); //切割层
        this._layCropper.onload = Bind(this, this.SetPos);
        //用来设置大小
        this._tempImg = document_createElement_x_x_x("img");
        this._tempImg.onload = Bind(this, this.SetSize);

        this.SetOptions(options);

        this.Opacity = Math.round(this.options.Opacity);
        this.Color = this.options.Color;
        this.Scale = !!this.options.Scale;
        this.Ratio = Math.max(this.options.Ratio, 0);
        this.Width = Math.round(this.options.Width);
        this.Height = Math.round(this.options.Height);

        //设置预览对象
     

你可能感兴趣的:(js截图)