我想在点击图像时以模态形式捕获图像上的光标坐标,但我在JavaScript上吮吸。我还希望模式窗体在点击图像时仅打开。当用户点击窗口中的任何位置时,模式表单当前弹出。任何能够帮助我获得以窗口为中心的模态表单的奖励标志!将TextBox.Value传递给模式窗体Label.Text OnClick
任何见解将不胜感激。
这是我到目前为止有:
HTML
<a onmouseover="document.body.style.cursor='crossHair'"
onmouseout="document.body.style.cursor='default'"
onmousemove="getXY(event)">
<img id="Image" src="../Images/TestImage.jpg" alt=""/></a><br/><br/>
X = <input type="text" id="xVal" size="1" readonly="true"/>
Y = <input type="text" id="yVal" size="1" readonly="true"/><br/><br/>
<div id="mask"></div>
<div id="container">
<div id="submitDialog" class="window"><br />
X-coordinate:<asp:Label ID="lblX" runat="server"></asp:Label><br/>
Y-coordinate:<asp:Label ID="lblY" runat="server"></asp:Label><br/>
的Javascript
function getXY(e) {
var txtX = document.getElementById("xVal");
var txtY = document.getElementById("yVal");
MouseX = (e).offsetX;
MouseY = (e).offsetY;
txtX.value = MouseX;
txtY.value = MouseY;
}
$(document.getElementById('#Image')).click(function() {
launchWindow('#submitDialog');
$(window).resize(function() {
var box = $('#container .window');
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(document).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
//Get the window height and width
var winH = $(document).height();
var winW = $(document).width();
//Set the popup window to center
box.css('top', winH/2 - winH);
box.css('left', winW/2 - winW/2);
});
});
function launchWindow(id) {
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(document).width();
//Get the window height and width
var winH = $(document).height();
var winW = $(document).width();
//Set heigth and width to mask to fill up the whole screen
//and mask position
$('#mask').css({ 'width': maskWidth, 'height': maskHeight });
$('#mask').css({ 'top': 0, 'left': 0});
//transition effect
$('#mask').fadeIn(500);
$('#mask').fadeTo("fast", 0.8);
//Set the popup window to center
$(id).css('top', winH/2 - winH);
$(id).css('left', winW/2 - winW/2);
//transition effect
$(id).fadeIn(500);
//These are not setting the label text :(
$('#lblX').text($('#xVal').val());
$('#lblY').text($('#yVal').val());
}
CSS
#mask
{
position:absolute;
z-index:9000;
background-color:#000;
display:none;
}
#container .window
{
position:relative;
width:300px;
height:490px;
display:none;
z-index:9999;
padding:20px;
padding-bottom: 40px;
background-color: white;
color:black;
}
#container
{
position: relative;
width: 0px;
height: 0px;
}
感谢您的及时响应詹姆斯。您的解决方案看起来很有希望,但不幸的是,当我尝试实施时,它并不奏效当单击图像时,模态窗体中的标签仍会弹出为空白,当单击窗口的任何部分时,模态窗体仍会弹出,而不仅仅是图像,并且居中计算比我的原始窗体更远: ( – 8thWonder 2012-03-28 12:38:54
哈哈真的吗?对此我很抱歉,我知道该怎么做,因为我已经完成了一百万次,我只是在SO中编写代码,所以我没有真正测试它,今天我会再试一次。 – 2012-03-28 19:54:31
这一切都很好,我仍然在努力,所以我猜先发帖的人会得到积分! – 8thWonder 2012-03-28 20:21:09