gpt4 book ai didi

javascript - 如何使图像(div)在网站内跟随光标?

转载 作者:行者123 更新时间:2023-11-28 00:12:18 24 4
gpt4 key购买 nike

此图像是光标轨迹图像的静态 div 副本。一个是固定的,另一个跟随光标。如何编写静态 div 图像以跟随光标?

引用此图片http://deverexdrawer.deviantart.com/art/Trailimage-538913342

Trailimage javascript 摘录

var trailimage=["images/contact/gardening-glove-cursor.png", , ]
var offsetfrommouse=[-110,5]
var displayduration=0

if (document.getElementById || document.all)
document.write('<div id="trailimageid" style="position:absolute;visibility:visible;left:0px;top:100px;width:1px;height:1px"><img border="0" src="'+trailimage[0]+'"></div>')

function followmouse(e){
var xcoord=offsetfrommouse[0]
var ycoord=offsetfrommouse[1]
if (typeof e != "undefined"){
xcoord+=e.pageX
ycoord+=e.pageY
}

</script>

静态div图像

...<img border="0" src="'+trailimage[0]+'"
onmousedown="this.src=trailimage[1]"
onmouseup="this.src=trailimage[0]" />...

假设

var trailimage=[
"images/contact/gardening-glove-cursor.png",
"images/contact/gardening-glove-cursor_down.png" ]

最佳答案

试试这个

http://jsfiddle.net/n4foofvm/1/

html

<div id="movingDiv">
<img id="barber" class="barber-image" src="1.jpg" />
</div>

CSS

#movingDiv{
width:20px;
height:20px;
position:absolute;
}

JavaScript

$(document).mousemove(function(e){
$("#movingDiv").css({left:e.pageX, top:e.pageY});
});

关于javascript - 如何使图像(div)在网站内跟随光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778931/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com