Демо кота
Поводи курсором возле кота
Код очень старый, до 2018го года)) не судите строго))
<script type="text/javascript" src="https://releases.jquery.com/git/jquery-git.min.js"></script>
<div class="parent__cat">
<svg viewBox="0 0 14 13" id="my_cat">
<path class="cat" fill="#303030" d="M12.9 6.9c0 2.5-2.6 4.7-5.7 4.7S1.4 9.4 1.4 6.9c0-1 .3-1.9 1-2.7.6-.7 1.5-1.3 2.5-1.6.7-.2 1.5-.3 2.3-.3 3.1-.1 5.7 2 5.7 4.6z" />
<path class="ear1" fill="#303030" d="M11.6,0.8c0.4,1.1,0.3,2.3,0,3.4L9.1,2.8C10.2,1.7,11.1,0.9,11.6,0.8z" />
<path class="ear" fill="#303030" d="M2.5,1c0.9,0.4,1.7,1.1,2.4,1.9L2.5,4.4C2,3.2,1.9,2,2.5,1L2.5,1z" />
<ellipse class="eye" id="eye" fill="#FFF" cx="9.2" cy="6.6" rx="1.1" ry=".8" />
<ellipse class="eye" fill="#FFF" cx="4.8" cy="6.6" rx="1.1" ry=".8" />
<ellipse class="pupils" id="pupils" fill="#303030" cx="4.8" cy="6.65" rx=".2" ry=".5" />
<ellipse class="pupils" id="pupils1" fill="#303030" cx="9.2" cy="6.65" rx=".2" ry=".5" />
<path class="moustache" stroke="#303030" stroke-width=".25" stroke-miterlimit="10" d="M13.8 8.1l-1.1-.2m1.2 2l-1.8-.8m1.1 2.5L11 10.1M.3 8.1l1.3-.2M.1 9.8l2-.8M.9 11.5l2.3-1.4" />
</svg>
</div>
<p>поводи курсором возле кота</p>
.parent__cat {
width: 260px;
margin: 0 auto;
}
.eye {
animation: eye 4s;
animation-iteration-count: infinite;
transform-origin: center;
}
@keyframes eye {
0% {
transform: scale(1, 1);
}
36% {
transform: scale(1, 1);
}
38% {
transform: scale(1, 0);
}
42% {
transform: scale(1, 0);
}
44% {
transform: scale(1, 1);
}
100% {
transform: scale(1, 1);
}
}
.ear {
animation: ear 7s;
animation-iteration-count: infinite;
transform-origin: center;
}
.ear1 {
animation: ear 7s;
animation-delay: 300ms;
animation-iteration-count: infinite;
transform-origin: center;
}
@keyframes ear {
0% {
transform: scale(1, 1);
}
37% {
transform: scale(1, 1);
}
40% {
transform: scale(1, 0);
}
43% {
transform: scale(1, 1);
}
100% {
transform: scale(1, 1);
}
}
$(document).ready(function() {
window.onmousemove = function(event) {
var object = document.getElementById("my_cat");
var svgDocument = object.contentDocument;
var pupils = document.getElementsByClassName("pupils");
x = event.pageX;
y = event.pageY;
for (var n = 0; n < pupils.length; n++) {
getCoords(pupils[n], x, y)
}
function getCoords(pupils, x, y) {
var box = pupils.getBoundingClientRect();
var y_pupils = box.top + pageYOffset,
x_pupils = box.left + pageXOffset;
x = (x - x_pupils) / 500;
y = (y - y_pupils) / 500;
if (x >= 1) x = 0.9;
if (y >= 1) y = 0.9;
if (x <= -1) x = -0.9;
if (y <= -1) y = -0.9;
var translate = "translate(" + x + "px," + y + "px)";
$(pupils).css({
'transform': translate
})
};
}
});