gpt4 book ai didi

javascript - 将 html 元素移向鼠标光标

转载 作者:行者123 更新时间:2023-12-02 14:29:53 24 4
gpt4 key购买 nike

我有一个 html 元素:<img src="./pic/char.png" width="30" height="30" alt="me">
我如何使用javascript不断地将这个html元素移向光标?预先感谢:)

最佳答案

您好,引用这个http://jsfiddle.net/wUAGP/440/

HTML

    <div class="moveAble">
<div class="info"><img src="https://pbs.twimg.com/profile_images/1498221863/Jodis_Gifts_logo_hi_res_normal.jpg" alt="info" /></div>
</div

>

JS

$(document).ready(function(){
var $moveable = $('.moveAble');
$(document).mousemove(function(e){
$moveable.css({'top': e.pageY,'left': e.pageX});
});
});

关于javascript - 将 html 元素移向鼠标光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37934281/

24 4 0
文章推荐: javascript - 将 JavaScript 变量传递给 html