我正在举这个小例子,我试图将图像置于光标的中心,基本上,当您单击时,光标应该位于图像的中心。由于我是初学者,我真的不知道如何才能实现这一目标。也许是通过使用类似的东西$(".theImg").height,但我认为我做错了,因为它不起作用。也许我必须使用transform...
$(document.body).click(function(event) {
x = event.pageX;
y = event.pageY;
console.log(x +", "+ y);
console.log(('theImg').height);
$(".paysage") .css({'position' : 'absolute', 'top': y, 'left' : x})
.prepend($('<img>',{ class:'theImg',
src:'https://www.30millionsdamis.fr/uploads/pics/conseils-erreurs-chat-1171.jpg'}))
$(".theImg").prev().remove();
});
body{
width: 100vw;
height: 100vh
}
.theImg{
width :20em;
height: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class = "paysage"> </div>
慕慕森
潇湘沐
相关分类