Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
溢出隐藏不使用jQuery.css单击事件_Jquery_Css_Jquery Animate - Fatal编程技术网

溢出隐藏不使用jQuery.css单击事件

溢出隐藏不使用jQuery.css单击事件,jquery,css,jquery-animate,Jquery,Css,Jquery Animate,我正在分配溢出:隐藏,但它似乎不起作用 html 我试图在div上实现滑动关闭效果。即使有其他方法,我也不确定为什么这不起作用。尝试交换它们 $('.hide_list').click(function() { $('.list-container').css("overflow","hidden"); $('.list-container').animate({width: "2px"}); }); 我认为,如果在使用动画时将高度或宽度设置为不同于0的值,jquery将消除

我正在分配
溢出:隐藏
,但它似乎不起作用

html

我试图在div上实现滑动关闭效果。即使有其他方法,我也不确定为什么这不起作用。

尝试交换它们

$('.hide_list').click(function() {
    $('.list-container').css("overflow","hidden");
    $('.list-container').animate({width: "2px"});
});

我认为,如果在使用动画时将高度或宽度设置为不同于0的值,jquery将消除溢出隐藏。使用“动画”方法的回调可以解决此问题:


这是因为动画结束后必须调用overflow:hidden。在动画过程中,jquery添加内联样式,并覆盖.css(“溢出”、“隐藏”)。下面是应该怎么写的


试着这样写:

        $("#div").stop(true,false).animate({
           width: '2px'
        },500);

不要担心.stop(true,false)-所做的只是确保事件不会继续运行。

是否有理由使用jquery设置溢出,这可以通过css完成,然后溢出不会被删除。同样,当使用代码时,li元素会得到额外的一行。可以通过给li元素一个宽度来停止此操作。

如果您试图隐藏“列表容器”,您可能应该使用以下方法:

$('.hide_list').click(function() {
    $('.list-container').animate({height: "2px"});
    $('.list-container').hide(2000);
});
还是无效

$('.hide_list').click(function() {
    $('.list-container').animate({width: "2px"});
    $('.list-container').css("display","none");
});

您的javascript中有错误。请尝试以下代码:

$('.hide_list').click(function() {
    $('.list-container').animate({width: "2px"});
$('.list-container').css({"overflow":"hidden"});
});

将下面的代码从

$('.list-container').animate({width: "10px"}); 

 $('.list-container').css("overflow","hidden");


你可能需要指定一个高度?@Tim这不起作用,不幸的是移动css中的
溢出:隐藏
设置;或者在动画制作之前,我们可以投票表决这个问题以帮助其他用户。我花了一段时间才发现问题,因为我认为问题出在我的脚本中,然后我认为问题出在我的css中。哇!这起作用了,真奇怪。我希望我们可以投票表决这个问题,以帮助其他用户。这让我有一段时间感到困惑,因为我认为错误是在我的脚本中的其他地方造成的。我之所以将溢出设置为隐藏,是因为当它设置为
2px
时,它仍然显示,好像溢出被接受为标准。谢谢。但我只是想交换一下,因为这也行+这很有效,谢谢。但我只是想交换一下,因为这也行+1.
$('.hide_list').click(function() {
    $('.list-container').animate({height: "2px"});
    $('.list-container').hide(2000);
});
$('.hide_list').click(function() {
    $('.list-container').animate({width: "2px"});
    $('.list-container').css("display","none");
});
$('.hide_list').click(function() {
    $('.list-container').animate({width: "2px"});
$('.list-container').css({"overflow":"hidden"});
});
$('.list-container').animate({width: "10px"}); 

 $('.list-container').css("overflow","hidden");
 $('.list-container').css("overflow","hidden");
    $('.list-container').animate({width: "10px"});