3.jQuery滑动,淡入淡出和动画效果

<!DOCTYPE html>

<html lang="en">



<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .animate {
            position: absolute;
            background-color: red;
            width: 300px;
            height: 100px
        }
    </style>
</head>

<body>
    <div>
        <ul>
            按钮
            <li>1</li>
            <li>1</li>
            <li>1</li>
        </ul>
        <ul>
            按钮
            <li>2</li>
            <li>2</li>
            <li>2</li>
        </ul>
        <ul>
            按钮
            <li>3</li>
            <li>3</li>
            <li>3</li>
        </ul>
    </div>

    <div>
        <p>淡入效果</p>
        <p>淡出效果</p>
        <p>淡入淡出切换</p>
        <p>修改透明度</p>
    </div>


    <div class="animate">动画效果</div>
</body>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

<script>
    // 1.滑动效果
    $(() => {
        //切换下拉滑动效果
        $("ul").children().slideUp()

        $("div>ul").hover(function () {
            //添加stop()同一时间只执行一个动画过渡效果,动画排队
            $(this).children("li").stop().slideToggle(300)
        }).css({
            backgroundColor: "red",
            width: "100px"
        })

    })


    // 2.淡入淡出,修改透明度
    $(() => {
        $("div p").css({
            backgroundColor: "blue",
            height: "100px",
            width: "100px"
        })
        // 渐隐
        $("div p").hover(function () {
            $(this).stop().fadeOut(1000)
        })
        // 渐显
        $("div p").mouseout(function () {
            $(this).stop().fadeIn(1000)
        })
        // 切换淡入淡出
        $("div p").hover(function () {
            $(this).stop().fadeToggle(1000)
        })

        // 修改透明度,实现遮罩效果
        $("div p").hover(function () {
            $(this).siblings().stop().fadeTo(1000, 0.5)
        }, function () {
            $(this).siblings().stop().fadeTo(1000, 1)
        })

    })


    //3.动画效果
    $(function () {
        $(".animate").hover(function () {
            $(this).stop().animate({
                //距离左边500
                left: 500,
                top: 300,
                width: 500
            })
        })

        $(".animate").mouseout(function () {
            $(this).stop().animate({
                left: 0,
                opacity: .5,
                top: 0
            })
        })
    })
</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值