热门关键字:
jquery > jquery教程 > jquery教程 > 使用jQueryanimate方法

使用jQueryanimate方法

363
作者:管理员
发布时间:2021/2/5 13:32:52
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3866
您可以简单地将jQueryanimate()方法与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-3.5.1.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>Note:</strong> Place mouse pointer over the box to play the animation.</p>
    <div class="box"></div>
</body>
</html>




如果您觉得本文的内容对您的学习有所帮助:支付鼓励



关键字:jQuery
友荐云推荐