web JQ 动画与循环

在这里插入图片描述

动画的使用

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>动画的展示</title>
    <style>
        #ball {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: gold;
            position: absolute;
            top: 50%;
            left: 50%;
        }
    </style>
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <div>
        <img id="img" src="imgs/头像.jpg" alt="">
    </div>
    <button id="btn">隐藏</button>
    <!-- 定义一个小球元素 -->
    <div id="ball">

    </div>
    <button id="move">移动</button>
    <script>
        $("#btn").on("click", function () {
            if ($(this).text() == "隐藏") {
                //淡出
                $("#img").fadeOut(1000, function () {
                    $("#btn").text("显示");
                });
            }
            else {
                //淡入
                $("#img").fadeIn(1000, function () {
                    $("#btn").text("隐藏");
                });
            }
        })

        // 自定义动画
        $("#move").on("click", function () {
            //淡入
            $("#ball").fadeIn(1000);

            //到移动 left 60%处
            $("#ball").animate({ left: "60%" });
            // 等待后移动
            setTimeout(function () {
                $("#ball").animate({ top: "30%" })
            }, 100);
            // 等待后移动
            setTimeout(function () {
                $("#ball").animate({ left: "50%" })
            }, 200);

            //等待后  淡出
            setTimeout(function () {
                $("#ball").animate({ top: "50%" }, function () {
                    $("#ball").fadeOut(1000);
                })
            }, 300);
        })

        //只能写一次
        // window.οnlοad=function(){
        //     alert("原生页面加载完成")
        // }
        // window.οnlοad=function(){
        //     alert("原生页面加载完成1")
        // }
        
        // 页面加载完成
        $(function () {
            alert("页面加载完成");
        })
        // $(function(){
        //     alert("页面加载完成2");
        // })
    </script>
</body>

</html>

循环遍历

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>遍历</title>
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <div>abc</div>
    <div>def</div>
    <div>ggg</div>

    <script>
        //使用each函数完成
        //写法:选择器.each(function(index, element)){}
            //index 索引号
            //element 原生元素
        $("div").each(function(index, element){
            console.log(index);
            console.log($(element));
            //获取元素内容
            console.log($(element).text())
        })
    </script>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

廷益--飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值