87,965
社区成员
发帖
与我相关
我的任务
分享
function image_preview_TipBox(id){
var picsrc = $("#pic_"+id+"").attr('srcdef');
//信息框
// var picsrc = $("img[modal='zoomImg']").attr("src");
//给body添加弹出层的html
$("body").append("<div class=\"mask-layer\">" +
" <div class=\"mask-layer-black\"></div>" +
" <div class=\"mask-layer-container\">" +
" <div class=\"mask-layer-imgbox auto-img-center\"></div>" +
" </div>" +
"</div>"
);
var img_index = $("#pic_"+id+"").index(this);//获取点击的索引值
var num = img_index;
function showImg() {
$(".mask-layer-imgbox").append("<p><img src=\"\" alt=\"\"></p>");
$(".mask-layer-imgbox img").prop("src", picsrc); //给弹出框的Img赋值
//图片拖拽
var $div_img = $(".mask-layer-imgbox p");
//绑定鼠标左键按住事件
$div_img.bind("mousedown", function (event) {
event.preventDefault && event.preventDefault(); //去掉图片拖动响应
//获取需要拖动节点的坐标
var offset_x = $(this)[0].offsetLeft;//x坐标
var offset_y = $(this)[0].offsetTop;//y坐标
//获取当前鼠标的坐标
var mouse_x = event.pageX;
var mouse_y = event.pageY;
//绑定拖动事件
//由于拖动时,可能鼠标会移出元素,所以应该使用全局(document)元素
$(".mask-layer-imgbox").bind("mousemove", function (ev) {
// 计算鼠标移动了的位置
var _x = ev.pageX - mouse_x;
var _y = ev.pageY - mouse_y;
//设置移动后的元素坐标
var now_x = (offset_x + _x ) + "px";
var now_y = (offset_y + _y ) + "px";
//改变目标元素的位置
$div_img.css({
top: now_y,
left: now_x
});
});
});
//当鼠标左键松开,接触事件绑定
$(".mask-layer-imgbox").bind("mouseup", function () {
$(this).unbind("mousemove");
});
//关闭
$(".mask-close").click(function () {
$(".mask-layer").remove();
});
$(".mask-layer-black").click(function () {
$(".mask-layer").remove();
});
}
showImg();
}