如何使图像(div)跟随网站中的光标?

时间:2015-06-11 10:59:41

标签: javascript jquery variables cursor jquery-animate

此图像是光标trailimage的静态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" ]

1 个答案:

答案 0 :(得分:1)

试试这个

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

HTML

func documentsDirectory() -> string {
    let documentsFolderPath = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask, UserDomainMask, true)[0] as String
    return documentsFolderPath
}

CSS

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

的javascript

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