Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
X:
95
Y:
80
css
body { height: 100vh; display: flex; justify-content: center; align-items: center; color: #FFF; background: rgb(84,92,97); background: radial-gradient(circle, rgba(84,92,97,1) 0%, rgba(23,41,48,1) 100%); } svg { width: 90vw; height: auto; background-color: transparent; //border: 2px dashed #FFF; } #control-point { cursor: grab; } #control-point:active { cursor: grabbing; } .coordinates { text-align: center; display: flex; justify-content: center; gap: 20px; display: none; }
JavaScript
const svg = document.querySelector('svg'); const curve = document.getElementById('curve'); const controlPoint = document.getElementById('control-point'); const posXLabel = document.querySelector('.posX'); const posYLabel = document.querySelector('.posY'); const svgViewBoxWidth = 190; let isMouseDown = false; let point = { x: 95, y: 80 }; function updateCurve(x, y) { let svgRect = svg.getBoundingClientRect(); let scale = svgRect.width / svgViewBoxWidth; let width = (svgRect.width / scale) - 5; let height = (svgRect.height / scale) - 6; // update point coordinates to mouse/touch position when dragging if (x && y) { point.x = Math.ceil((x - svgRect.x) / scale); point.y = Math.ceil((y - svgRect.y) / scale); } // clamp the coordinates to the limits of the SVG viewbox point.x = point.x < 5 ? 5 : point.x; point.y = point.y < 5 ? 5 : point.y; point.x = point.x > width ? Math.ceil(width) : point.x; point.y = point.y > height ? Math.ceil(height) : point.y; // update coordinate labels posXLabel.textContent = point.x.toFixed(2); posYLabel.textContent = point.y.toFixed(2); // update coordinates for control point and curve controlPoint.setAttribute('cx', point.x); controlPoint.setAttribute('cy', point.y); curve.setAttribute('d', curve.getAttribute('d').replace(/Q (\d+(\.\d+)?) (\d+(\.\d+)?)/, `Q ${point.x} ${point.y}`)); } function onMouseDown() { isMouseDown = true; } function onMouseMove(ev) { if (isMouseDown) { updateCurve(ev.clientX, ev.clientY); } } function onMouseUp() { isMouseDown = false; // animate the control point and curve back to // the initial positions with a bouncy effect // using the anime.js animation library anime({ targets: point, x: 95, // target X coordinate y: 80, // target Y coordinate duration: 1000, easing: 'easeOutElastic(1.5, 0.2)', update: function() { updateCurve(); } }); } controlPoint.addEventListener('mousedown', onMouseDown); controlPoint.addEventListener('touchstart', onMouseDown); document.addEventListener('mousemove', onMouseMove); document.addEventListener('touchmove', (ev) => { updateCurve(ev.touches[0].clientX, ev.touches[0].clientY); }); document.addEventListener('mouseup', onMouseUp); document.addEventListener('touchend', onMouseUp);
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>弹力球-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号