0
我的問題是如何顯示股利或框元素與位置固定的中央底部單擊目標集光標位置DIV固定中心底部的目標
例如:
<p>
<button class="target-show">target show</button>
<button class="target-show">target show</button>
</p>
<hr><hr><hr><hr><hr><hr><hr>
<hr><hr><hr><hr><hr><hr><hr>
<div id="demo"></div>
<p>
<button class="hidden-div">hidden div</button>
</p>
CSS:
p {
text-align:center;
}
button {
width : 50px;
}
#demo {
display :none;
padding : 25px;
background : red ;
width : 100px;
height : 100px;
}
的jQuery:
$(function() {
$(".target-show").click(function(e) {
var target = $('.target-show');
var div = $('#demo');
var left = e.clientX - target.width()/2;
var top = e.clientY - target.height()/2;
div.css({'position': 'absolute', 'left': left, 'top': top}).show();
});
$(".hidden-div").click(function() {
$("#demo").hide();
});
});
$(function() {
$(".target-show").click(function(e) {
\t var target \t = \t $('.target-show');
\t \t \t var div \t \t \t = \t $('#demo');
var left \t \t = e.clientX - target.width()/2;
var top \t \t = e.clientY - target.height()/2;
div.css({'position': 'absolute', 'left': left, 'top': top}).show();
});
$(".hidden-div").click(function() {
\t \t \t $("#demo").hide();
\t });
});
p {
text-align:center;
}
button {
width : 50px;
}
#demo {
display :none;
padding : 25px;
background : red ;
width : 100px;
height : 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
<button class="target-show">target show</button>
<button class="target-show">target show</button>
</p>
<hr><hr><hr><hr><hr><hr><hr>
<hr><hr><hr><hr><hr><hr><hr>
<div id="demo"></div>
<p>
<button class="hidden-div">hidden div</button>
</p>