js截图
来源:互联网 发布:世界上第一个软件 编辑:程序博客网 时间:2024/05/16 06:02
首先要准备4个js文件:
1)prototype.js
var Class = {
create:function() {
return function() { this.initialize.apply(this, arguments); }
}
}
var Extend = function(destination, source) {
for (varproperty in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
returnfunction() {
return fun.apply(object, arguments);
}
}
var BindAsEventListener = function(object, fun) {
var args =Array.prototype.slice.call(arguments).slice(2);
returnfunction(event) {
return fun.apply(object, [event ||window.event].concat(args));
}
}
var CurrentStyle = function(element) {
returnelement.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);
//设置预览对象
1)prototype.js
var Class = {
}
var Extend = function(destination, source) {
}
var Bind = function(object, fun) {
}
var BindAsEventListener = function(object, fun) {
}
var CurrentStyle = function(element) {
}
function addEventHandler(oTarget, sEventType, fnHandler) {
};
function removeEventHandler(oTarget, sEventType, fnHandler) {
};
2)ImgCropper.js
//图片切割
var ImgCropper = Class.create();
ImgCropper.prototype = {