圆脉动增量
Circle pulsation increments
本文关键字:脉动 更新时间:2023-09-26
我有下面的工作代码,创建一个圆圈在画布上的图像区域和脉动动画。我的问题是,如果我点击两次红色圆圈,它会跳动得更快,如果再次点击,它会再次快速跳动。如何将代码改变,使节奏脉动一致。
这是我的HTML
<!DOCTYPE html>
<html>
<head>
<title>HTML5 input </title>
<meta name="viewport" content="user-scalable=no, initial-scale=1, minimum-scale=1, width=device-width" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<style>
canvas
{
pointer-events: none; /* make the canvas transparent to the mouse - needed since canvas is position infront of image */
position: absolute;
}
area{
position: absolute;
border:none;
}
</style>
</head>
<body>
<body id="myBodyId" >
<canvas id='canvas'></canvas>
<center>
<div id="myDiv1">
<img src="https://s12.postimg.org/sflskn1y5/shapes.jpg" id="pinch-zoom-image-id" usemap="#image-map"/>
</div>
<map name="image-map">
<area shape="circle" onclick="getid(this.coords)" coords="101,81,36" href="#">
<area shape="circle" onclick="getid(this.coords)" coords="148,81,12" nohref >
<area shape="circle" onclick="getid(this.coords)" coords="100,81,59" href="#">
</center>
</body>
</html>
</body>
</html>
脚本function byId(e){return document.getElementById(e);}
window.onload = function(){
}
var hdc;
var angle = 0;
var coord;
var requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
function getid(coordStr){
coord = coordStr.split(',');
myHover();
}
var ringRadius = 0;
var ringCounter = 0;
function myHover()
{
var img = byId('pinch-zoom-image-id');
var x,y, w,h;
// get it's position and width+height
x = img.offsetLeft;
y = img.offsetTop;
w = img.clientWidth;
h = img.clientHeight;
// move the canvas, so it's contained by the same parent as the image
var imgParent = img.parentNode;
var can = byId('canvas');
imgParent.appendChild(can);
// place the canvas in front of the image
can.style.zIndex = 1;
// position it over the image
can.style.left = x+'px';
can.style.top = y+'px';
// make same size as the image
can.setAttribute('width', w+'px');
can.setAttribute('height', h+'px');
// get it's context
hdc = can.getContext('2d');
// set the 'default' values for the colour/width of fill/stroke operations
hdc.fillStyle = 'red';
hdc.strokeStyle = 'red';
hdc.lineWidth = 4;
var can = document.getElementById("canvas");
hdc = can.getContext('2d');
var canvasWidth = can.width;
var canvasHeight = can.height;
hdc.clearRect(0, 0, canvasWidth, canvasHeight);
// color in the background
hdc.fillStyle = "#EEEEEE";
//hdc.fillRect(0, 0, canvasWidth, canvasWidth);
hdc.beginPath();
var radius = 5 + 50 * Math.abs(Math.cos(angle));
hdc.arc(coord[0], coord[1], radius, 0, Math.PI * 2);
hdc.closePath();
//console.log("radius"+radius);
hdc.strokeStyle = '#003300';
hdc.stroke();
angle += Math.PI / 84;
requestAnimationFrame(myHover);
}
问题是每次点击圆圈时调用递归函数myHover
。如果圆圈是脉动,我建议存储,如果它是:
myHover
。var pulsating = false
window.getid = function(coordStr) {
coord = coordStr.split(',');
if (!pulsating) {
pulsating = true
myHover();
}
}
点击这里查看:https://jsfiddle.net/fbooygo4/
相关文章:
- 调整窗口大小时,可拖动的对象会出现在容器外部
- 删除对HTML元素的拖动
- jQuery UI可排序-多连接列表拖动
- 禁用SVG拖动
- 旋转后拖动对象
- JQuery UI可拖动潜水与滚动棒到鼠标
- jsPlumb-拖动克隆而不进行复制
- 当我在节点上拖动鼠标时,我如何防止使用d3.ehavior.zoom().on(“缩放”,重绘)
- 在Raphael JS中创建脉动(循环)背景的最简单方法
- JVector地图脉动标记
- 在jQuery UI中,如何防止连续调用时运行数百万次的“脉动”效应
- 延迟 jQuery 脉动与计时器相结合
- jQuery脉动代码与滚动图像jQuery代码冲突
- .png徽标上的脉动发光效果
- 只有脉动文本CSS3
- 圆脉动增量
- Javascript发光/脉动效果停止点击
- 脉动效应不起作用
- Jquery从不同的颜色脉动
- Jquery脉动改变颜色或图像