【问题标题】:how to use a single jquery to change a div's display property and animate如何使用单个 jquery 更改 div 的显示属性和动画
【发布时间】:2013-01-27 18:10:08
【问题描述】:

我正在制作一个页面,单击一个按钮并使用 jquery animate 命令打开一个完整的菜单。然后当您单击十字图片时,它会再次使用动画命令关闭。但问题是它的位置是固定的,它包含从 1 到 30 的数字。因此,当您隐藏 div 时,它会隐藏,但数字仍然在左侧可见,直到或除非您没有将其显示属性更改为 none

//this resets the size of div to 0
$(document).ready(function(){
$("#fullmenu").animate({
  height:'0%',
  width:'0%'
  });
  });
  //This opens the div
    $(document).ready(function(){
  $("#imgdot").click(function(){
  $("#fullmenu").animate({
height:'90%',
width:'90%',
    });
  });
});
 //This closes the div when the image cross is clicked
$(document).ready(function(){
  $("#cross").click(function(){
    $("#fullmenu").animate({
            height:'0%',
            width:'0%'
      });
   });
});

我的问题是如何将 display 属性更改为 none 并同时为 div 设置动画是单个函数

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    jQuerys 动画通常不会影响 div 的子元素,

    你可以试试这个:

    $("#fullmenu").animate({
            height:'0%',
            width:'0%'
    }).children().hide();
    

    【讨论】:

      【解决方案2】:

      使用这个

      $('#foo').fadeOut("slow", function(){
          var div = $("<div id='foo'>test2</div>").hide();
          $(this).replaceWith(div);
          $('#foo').fadeIn("slow");
      });
      

      【讨论】:

        【解决方案3】:
        Css can be changed as $("#divId").css('display','none');
        
        $(document).ready(function(){
        
          $("#cross").click(function(){
        
            $("#fullmenu").animate({
        
                    height:'0%',
                    width:'0%'
              },complete:function(){
        
        $("#fullmenu").css('display','none')
        });
           });
        });
        
        
        That said, you could use :
        
        $(document).ready(function(){
        
          $("#cross").click(function(){
        
            $("#fullmenu").slideUp();
           });
        

        【讨论】:

        • 当我编写您的代码时,整个 jquery 文件将无法工作。我不希望它滑动、隐藏或褪色等。我只想为它设置动画,这样当你关闭它时,它就会得到收缩效果
        • 试试这个: $("#fullmenu").animate({height:'0%', width:'0%' }, 5000, function() { $("#fullmenu") .css('display','none') // 动画完成。});
        • 你的意思是:`$(document).ready(function(){ //输入 $("#cross").click(function(){ //输入 $("#fullmenu" ).animate({height:'0%', width:'0%' }, 5000, //enterfunction(){ //输入 $("#fullmenu").css('display','none') / /输入 }); //输入 }); //输入 }); //输入 });
        • 不,它仍然无法运行。整个文件不会运行。要我给你附件吗
        • 能否请您创建一个小提琴。我认为这会有所帮助。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-15
        • 2011-04-04
        • 1970-01-01
        相关资源
        最近更新 更多