Вы можете просто использовать jQuery-метод animate()
в сочетании с методами mouseenter()
и mouseleave()
для анимации высоты элемента <div>
при наведении курсора мыши.
Давайте посмотрим следующий пример, чтобы понять, как это работает:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Animate Div Height on Hover</title>
<style>
.box{
width: 400px;
height: 150px;
background: #f0e68c;
border: 1px solid #a29415;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
var boxHeight = $(".box").height();
$(".box").mouseenter(function(){
$(this).animate({
height: "300"
});
}).mouseleave(function(){
$(this).animate({
height: boxHeight
});
});
});
</script>
</head>
<body>
<p><strong>Заметка:</strong> Наведите указатель мыши на поле, чтобы воспроизвести анимацию.</p>
<div class="box"></div>
</body>
</html>