jq常用函数

hide();

<div class="box">big box</div>
$('.box').hide(5000, function(){ console.log('hhhhh'); }); //hide() h设置隐藏元素 //5000 是用5000ms内实现这个元素消失效果 // 内部函数是回调函数callback,是5000ms后调用的函数
   //也可以不接收参数
   //接收的参数是时间值 和 一个执行结束后的回调

(css样式省略)

浏览器中元素会逐渐消失,消失后控制台打印内容

show();

   .hide-box {
        height: 200px;
        background-color: rgb(25, 99, 25);
        font-size: 60px;
        text-align: center;
        line-height: 200px;
        color: white;
        display: none;
    }


    <div class="hide-box">big box</div>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>

    <script>
        $('.hide-box').show(5000, function(){
            console.log('hhhhh');
        });
   </script>

show(); 让一个隐藏的按钮显示

举个栗子:

点击按钮让图片切换隐藏显示

 .box {
        height: 200px;
        background-color: rgb(25, 99, 25);
        font-size: 60px;
        text-align: center;
        line-height: 200px;
        color: white;
    }


    <button class="btn">button</button>
    <div class="box">big box</div>
 $('.btn').click(function(){
            $('.box').toggle(5000,function(){
                console.log(11);
                
            });
        });
        // 可以不接收参数
        // 可以接受一个时间参数,作为切换的时间
        //也可以接受一个回调函数,执行一次切换执行一次回调

猜你喜欢

转载自www.cnblogs.com/sandraryan/p/11525968.html