У меня есть круг, который следует за курсором, и я также заставил его расширяться, когда навожу курсор на любой текст. Проблема в том, что я пытаюсь добавить transition: 2s; в CSS, чтобы он плавно расширялся. Когда я добавляю его, это разрушает мою анимацию JavaScript, поэтому мне было интересно, могу ли я добавить только время перехода к моменту расширения круга.
Я также устал добавлять transition: 2s; только к классу .mouseFollowCircle.big, но это вызывает те же проблемы в JavaScript, только когда я навожу курсор на текст.
document.addEventListener('DOMContentLoaded', () => {
const interBubble = document.getElementById('circle');
let curX = 0;
let curY = 0;
let tgX = 0;
let tgY = 0;
function move() {
curX += (tgX - curX) / 10;
curY += (tgY - curY) / 10;
interBubble.style.transform = `translate(${Math.round(curX)}px, ${Math.round(curY)}px)`;
requestAnimationFrame(() => {
move();
});
}
window.addEventListener('mousemove', (e) => {
tgX = e.clientX;
tgY = e.clientY;
if (e.target.tagName === 'P' ||
e.target.tagName === 'A' ||
e.target.tagName === 'BUTTON' ||
e.target.parentNode.tagName === 'BUTTON') {
interBubble.classList.add('big');
} else {
interBubble.classList.remove('big');
}
});
move();
});Body {
background-color: black;
overflow: hidden;
}
div {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
p {
color: white;
font-size: 30px;
}
.mouseFollowCircle {
width: 50px;
height: 50px;
border: 3px solid white;
border-radius: 999px;
position: absolute;
z-index: 999;
top: -25px;
left: -25px;
box-shadow: 0 0 10px white;
pointer-events: none;
backdrop-filter: blur(2px);
}
.mouseFollowCircle.big {
width: 70px;
height: 70px;
border-radius: 999px;
border: 1px solid white;
position: absolute;
z-index: 999;
top: -35px;
left: -35px;
box-shadow: 0 0 10px white;
pointer-events: none;
backdrop-filter: blur(2px);
}<div><p>Hello</p></div>
<section class = "mouseFollowCircle" id = "circle"></section>


![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Чтобы сделать эффект расширения плавным для круга, следующего за курсором мыши, просто настройте эти свойства в классе .mouseFollowCircle:
transition: width 1s ease, height 1s ease, border 1s ease, top 1s ease, left 1s ease;
document.addEventListener('DOMContentLoaded', () => {
const interBubble = document.getElementById('circle');
let curX = 0;
let curY = 0;
let tgX = 0;
let tgY = 0;
function move() {
curX += (tgX - curX) / 10;
curY += (tgY - curY) / 10;
interBubble.style.transform = `translate(${Math.round(curX)}px, ${Math.round(curY)}px)`;
requestAnimationFrame(() => {
move();
});
}
window.addEventListener('mousemove', (e) => {
tgX = e.clientX;
tgY = e.clientY;
if (e.target.tagName === 'P' ||
e.target.tagName === 'A' ||
e.target.tagName === 'BUTTON' ||
e.target.parentNode.tagName === 'BUTTON') {
interBubble.classList.add('big');
} else {
interBubble.classList.remove('big');
}
});
move();
});Body {
background-color: black;
overflow: hidden;
}
div {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
p {
color: white;
font-size: 30px;
}
.mouseFollowCircle {
width: 50px;
height: 50px;
border: 3px solid white;
border-radius: 999px;
position: absolute;
z-index: 999;
top: -25px;
left: -25px;
box-shadow: 0 0 10px white;
pointer-events: none;
backdrop-filter: blur(2px);
transition: width 1s ease, height 1s ease, border 1s ease, top 1s ease, left 1s ease;
}
.mouseFollowCircle.big {
width: 70px;
height: 70px;
border-width: 1px;
top: -35px;
left: -35px;
}<div><p>Hello</p></div>
<section class = "mouseFollowCircle" id = "circle"></section>
transition: 2sприменяет 2-секундный переход ко всем свойствам, которые подвергаются изменениям, включаяtranslate. Попробуйтеtransition: 2s, translate 0s, чтобы явно указать нулевую продолжительность перехода для свойстваtranslate.