想实现ASP.NET实现在线截图的功能,需要使用两部分代码,请注意查看相应文章。
这里是JS代码。
一、JS代码
var x, y;
var old_position = {};
var offset = {};
$(document).ready(hide);
function hide() {
$("#div_caijian").fadeTo("slow", 0.5);
$("#div_caijian").mousedown(function (e) {
old_position = { X: e.clientX, Y: e.clientY };
offset = $("#div_caijian").offset();
$("#div_caijian").css({ "background-color": "White" });
var x1 = e.clientX - offset.left;
var y1 = e.clientY - offset.top;
$("#div_caijian").mousemove(function (k) {
offset = $("#div_caijian").offset();
if ((k.clientX - x1 - 73) <= 0) {
k.clientX = 73 + x1;
}
if ((k.clientX - x1 - 73) >= 155) {
k.clientX = 155 + 73 + x1;
}
if ((k.clientY - y1 - 63) <= 0) {
k.clientY = 63 + y1;
}
if ((k.clientY - y1 - 63) >= 115) {
k.clientY = 115 + 63 + y1;
}
x = k.clientX - x1;
y = k.clientY - y1;
$("#div_caijian").css({
left: x,
top: y
});
var x2 = (offset.left - 73) / 155 * 100;
var y2 = (offset.top - 63) / 115 * 75;
$("#img_liulan").css({
left: 0 - x2,
top: 0 - y2
});
$("#txt_left").val(offset.left - 73);
$("#txt_top").val(offset.top - 63);
});
$("#div_caijian").mouseup(function (k) {
$("#div_caijian").css({ "background-color": "transparent" });
$("#div_caijian").unbind("mousemove");
});
});
$(document).mouseup(function () {
$("#div_caijian").css({ "background-color": "transparent" });
$("#div_caijian").unbind("mousemove");
});
};