点击图片获取鼠标点击位置坐标点(距顶部和左边的百分比)

 // 选点
            $(".e-up-img").click(function (e) {
                that.xx = e.originalEvent.x || e.originalEvent.layerX || 0;//屏幕x坐标
                that.yy = e.originalEvent.y || e.originalEvent.layerY || 0;//屏幕y坐标

                var img_w = $(this).width();
                var img_h = $(this).height();
                var img_left = $(this).offset().left - $(document).scrollLeft();
                var img_top = $(this).offset().top - $(document).scrollTop();
                that.img_x = ((that.xx - img_left) / img_w) * 100 + '%';
                that.img_y = ((that.yy - img_top) / img_h) * 100 + '%';

            });

 

posted @ 2019-07-12 15:37  怪咖咖  阅读(2327)  评论(0编辑  收藏  举报