Jquery显示和隐藏div

时间:2016-09-06 12:37:29

标签: jquery

我有3个div如下

A*

点击按钮我想以下列方式显示div

  

第1步:隐藏div1
  第2步:显示spinnerdiv几毫秒说3000   第3步:隐藏spinnerdiv并显示div2

我尝试了以下方法,但它无法正常工作:

let bezierPath              = UIBezierPath(ovalIn: CGRect(x: 80, y: 200, width: 100, height: 100))

let shapeLayer              = CAShapeLayer()
shapeLayer.path             = bezierPath.cgPath
shapeLayer.fillColor        = UIColor.clear.cgColor
shapeLayer.strokeColor      = UIColor.white.cgColor
shapeLayer.lineWidth        = 3
shapeLayer.shadowPath       = bezierPath.cgPath
shapeLayer.shadowColor      = UIColor.black.cgColor
shapeLayer.shadowOffset     = CGSize(width: 0, height: 0)
shapeLayer.shadowOpacity    = 1

containerView.layer.addSublayer(shapeLayer)

4 个答案:

答案 0 :(得分:2)

使用setTimeout

进行尝试
$("#div1").hide();
$("#spinnerDiv").show();
setTimeout(function() {
    $("#spinnerDiv").hide();
    $("#div2").show();
}, 3000);

答案 1 :(得分:1)

尝试使用回调而不是hide()作为函数的第一部分,因为我不是延迟的粉丝,我会使用setTimeout:

$("button").click(function(){
    $("#div1").fadeOut(1, function () {
        var s = $("#spinnerDiv");
        s.show();
        setTimeout(function () {
            s.hide();
            $("#div2").show();
        }, 3000);
    });
}

答案 2 :(得分:1)

您是否尝试过使用setTimeout

button click function(){
     $("#div1").hide();
     $("#spinnerDiv").show();

     setTimeout(function () {
        $('#spinnerDiv').hide();
        $("#div2").show();
     }, 3000);

}

答案 3 :(得分:0)

你在这里

function thisAction(){
     $("#div1").hide();
     $("#spinnerDiv").hide();
      $("#div2").hide();
     
     $("#spinnerDiv").show().delay(3000).queue(function () {
                $(this).hide();
                $("#div2").show();
            });

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
 <div id="div1">div 1</div>
 <div id="spinnerDiv" style="display:none"> spinnerDiv</div>
 <div id="div2" style="display:none">div2</div>

<button onclick='thisAction()' >

相关问题