为什么我不能点击我的函数来显示和隐藏

Why I can not click on my function to show and hide?

本文关键字:显示 隐藏 函数 我的 不能 为什么      更新时间:2023-09-26

嘿,我在重写代码时遇到困难,但是单击以显示时它不起作用。如何解决此问题。代码工作打开 500,然后假设通过单击工作。但它不起作用。这是代码:

var timer;
$(".c_left").animate({ marginRight: "30px"}, "slow");
$(".c_right").animate({ marginRight: "215px"}, "slow", function () {
    timer = setTimeout(function () {
        $(".c_left").animate({ marginRight: "-155px"}, "slow");
        $(".c_right").animate({ marginRight: "30px"}, "slow");
    }, 500);
}); 
$(".icon-menu-2").click(function show() {
    $(".c_left").show.animate({ width: 200, marginRight: 30, display: 'toggle'}, 'slow');
    $(".c_right").show.animate({ marginRight:215, display:'toggle'}, 'slow', function () {
        clearTimeout(timer);
        });
}, function hide() {
    $(".c_left").animate({ marginRight: -155, display: 'toggle'}, 'slow');
    $(".c_right").animate({ marginRight:30, display:'toggle'}, 'slow');
    });

http://jsfiddle.net/jL5hU/

如何修复我的代码?

正如bfvareto评论的那样.show()是一个函数,你不能只用.show来调用它

你在这里也有奇怪的代码:.click(function show() {.不太确定你的意思,无论如何试试我的代码建议......

var timer; var open;
$(".c_left").animate({ marginRight: "30px"}, "slow");
$(".c_right").animate({ marginRight: "215px"}, "slow", function () {
    timer = setTimeout(function () {
        $(".c_left").animate({ marginRight: "-155px"}, "slow");
        $(".c_right").animate({ marginRight: "30px"}, "slow");
        open = false;
    }, 500);
}); 
$(".icon-menu-2").click(function() {
    if(open){
        $(".c_left").animate({ marginRight: "-155px"}, "slow");
        $(".c_right").animate({ marginRight: "30px"}, "slow");
    } else {
        $(".c_left").animate({ marginRight: "30px"}, "slow");
        $(".c_right").animate({ marginRight: "215px"}, "slow");            
    }
    open = !open;
});

在这里演示