$cards.forEach(function($card) {
$card.addEventListener("mousemove", function(e) {
var pos = [e.offsetX, e.offsetY];
e.preventDefault();
if (e.type === "touchmove") {
pos = [e.touches[0].clientX, e.touches[0].clientY];
}
var l = pos[0];
var t = pos[1];
var h = $card.clientHeight;
var w = $card.clientWidth;
var px = Math.abs(Math.floor(100 / w * l) - 100);
var py = Math.abs(Math.floor(100 / h * t) - 100);
var pa = (50 - px) + (50 - py);
var lp = (50 + (px - 50) / 1.5);
var tp = (50 + (py - 50) / 1.5);
var px_spark = (50 + (px - 50) / 7);
var py_spark = (50 + (py - 50) / 7);
var p_opc = 20 + (Math.abs(pa) * 1.5);
var ty = ((tp - 50) / 2) * -1;
var tx = ((lp - 50) / 1.5) * 0.5;
var grad_pos = `background-position: ${lp}% ${tp}%;`
var sprk_pos = `background-position: ${px_spark}% ${py_spark}%;`
var opc = `opacity: ${p_opc / 100};`
var tf = `transform: rotateX(${ty}deg) rotateY(${tx}deg)`;
var style = `
.card:hover:before { ${grad_pos} } /* gradient */
.card:hover:after { ${sprk_pos} ${opc} } /* sparkles */
`;
$cards.forEach(card => card.classList.remove("active"));
$card.classList.remove("animated");
$card.setAttribute("style", tf);
$style.innerHTML = style;
if (e.type === "touchmove") {
return false;
}
clearTimeout(x);
});
$card.addEventListener("mouseout", function() {
var $card = this;
$style.innerHTML = "";
$card.removeAttribute("style");
x = setTimeout(function() {
$card.classList.add("animated");
}, 2500);
});
$card.addEventListener("touchend", function() {
var $card = this;
$style.innerHTML = "";
$card.removeAttribute("style");
x = setTimeout(function() {
$card.classList.add("animated");
}, 2500);
});
$card.addEventListener("touchcancel", function() {
var $card = this;
$style.innerHTML = "";
$card.removeAttribute("style");
x = setTimeout(function() {
$card.classList.add("animated");
}, 2500);
});
});
To stop the cards from moving on their own, you need to remove the animation that runs on them by default and only make them move when there's a user interaction (e.g., mouse movement or touch).
Let’s make the adjustments:
Remove the animated class initially from the card.
Completely remove the @keyframes holoCard and associated classes that trigger the animation.
Update the JavaScript to remove references to the animated class.