我有一个HTML-5画布,其中有一个动画的圆圈。请参阅以下JS代码。
function doFirst(){
canvas = document.getElementById('myCanvas');
context = canvas.getContext('2d');
centerX = canvas.width / 4;
centerY = canvas.height / 4;
radius = 20;
dy=4;
drawCircle(centerX,centerY,radius);
myVar=setInterval(moveCirc,40);
}
function moveCirc(){
context.clearRect(0,0,canvas.width,canvas.height);
drawCircle(centerX,centerY,radius);
centerY+=dy;
if(centerY>canvas.height-50)
clearInterval(myVar);
}
function drawCircle(x,y,r){
context.lineWidth = 2;
context.strokeStyle = '#003300';
context.fillStyle = 'blue';
context.beginPath();
context.arc(x, y, r, 0, 2 * Math.PI, true);
context.stroke();
context.fill();
}
window.addEventListener("load",doFirst,false);
我希望每当用户将鼠标悬停在圆圈上时,动画应该暂停并显示一条消息。当用户将鼠标移出圆圈时,动画应该从其暂停的位置再次开始,并且消息应该消失。请帮助我实现此功能。
答案 0 :(得分:0)
如果您正在使用css3动画 鼠标悬停更改css属性
-webkit-animation-play-state: 暂停 暂停你的动画;
并从该点再次开始动画更改css属性
-webkit-animation-play-state: 正在运行
来源:http://css-infos.net/property/-webkit-animation-play-state
基于webkit的浏览器NB “ -webkit ”;使用“ -moz ”代表Mozilla,“ -o ”代表歌剧等。