简体   繁体   English

为什么我不能单击功能来显示和隐藏?

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

Hey I am having difficulty rewriting a code, but it is not working when clicking to show. 嘿,我很难重写代码,但是单击显示时它不起作用。 How can I fix this issue. 我该如何解决此问题。 The code works opens up 500 then is suppose to work by click. 代码工作打开500,然后单击即可工作。 But it does not work. 但这行不通。 Here is the code: 这是代码:

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/ http://jsfiddle.net/jL5hU/

How can I fix my code? 如何修复我的代码?

As bfvareto commented .show() is a function and you cannot call it with just .show 正如bfvareto所评论的.show()是一个函数,您不能仅使用.show来调用它。

You had strange code here also: .click(function show() { . Not quite sure what you mean there, anyway try my code suggestion... 您在这里也有奇怪的代码: .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;
});

Demo here 在这里演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM