【发布时间】:2014-10-31 16:03:49
【问题描述】:
我想使用 gif 图像制作鼠标效果,但问题是图像不是从头开始的。
html代码:<div style="width: 100px;height: 100px;background: red;" onclick="myFunction(this,event)"></div>
javascript代码:
function myFunction(ele,e)
{
var x = e.clientX - 15;
var y = e.clientY - 15;
var effect = document.createElement("DIV");
effect.style.background="url('http://s12.postimg.org/piulwsk61/image.gif')";
effect.style.backgroundSize="100% 100%";
effect.style.width="75px";
effect.style.height="75px";
effect.style.zIndex="1";
effect.style.position="fixed";
effect.style.top=y;
effect.style.left=x;
ele.appendChild(effect);
setTimeout(function(){ele.removeChild(effect);},700);
}
问题已解决:
javascript 代码:
function myFunction(ele,e)
{
var x = e.clientX - 15;
var y = e.clientY - 15;
var effect = document.createElement("IMG");
effect.style.src="http://s12.postimg.org/piulwsk61/image.gif";
effect.style.width="75px";
effect.style.height="75px";
effect.style.zIndex="1";
effect.style.position="fixed";
effect.style.top=y;
effect.style.left=x;
ele.appendChild(effect);
setTimeout(function(){ele.removeChild(effect);},700);
}
【问题讨论】:
-
这是动画 GIF 吗?
-
@aj_r 不,图像加载完成后,我第一次点击 div 时它会从头开始,但如果我再次点击它会从不同的地方开始。
-
@torazaburo 是的。