简体   繁体   English

jQuery if语句徽标出现问题。 没有回应我的期望

[英]having trouble with jQuery if statement logo. Not responding how I expected

The basic premise of my site is six large boxes that shrink down into a graphical menu bar when you click any of them. 我的网站的基本前提是六个大框,当您单击其中的任意一个时,它们会缩小为图形菜单栏。 An extra icon is added for the home button. 为主页按钮添加了一个额外的图标。

In order to position the boxes correctly in the first grid layout, I included a few extra classes such as margin-zero , bottom-left and bottom-right . 为了在第一个网格布局中正确放置框,我添加了一些额外的类,例如margin-zerobottom-leftbottom-right I need to remove these classes when the images are shrunk down, and bring them back when they're expanded to full size. 当图像缩小时,我需要删除这些类,并在将它们扩展到完整大小时将它们放回原处。

So, I created a little if statement. 因此,我创建了一些if语句。

var counter = 0;

if(counter = 0) {
    jQuery(".two").toggleClass( "two-menu" );
    jQuery(".four").toggleClass( "four-menu" );
    jQuery(".images").toggleClass( "images-menu" );
    jQuery(".home").toggleClass( "home-menu" );

    jQuery(".four").removeClass( "bottom-left" );
    jQuery(".four").removeClass( "bottom-right" );
    jQuery(".two").removeClass( "margin-zero" );

    var counter = 1;
} else {
    jQuery(".two").toggleClass( "two-menu" );
    jQuery(".four").toggleClass( "four-menu" );
    jQuery(".images").toggleClass( "images-menu" );
    jQuery(".home").toggleClass( "home-menu" );

    jQuery(".four").addClass( "bottom-left" );
    jQuery(".four").addClass( "bottom-right" );
    jQuery(".two").addClass( "margin-zero" );

    var counter = 0;
}

To me it looks like this should work. 在我看来,这应该可行。 However, in my JSFiddle prototype, it doesn't. 但是,在我的JSFiddle原型中却没有。 Here is the link, so you can see all of the code and how certain boxes just off the page. 这是链接,因此您可以查看所有代码以及页面附近的某些框。

http://jsfiddle.net/NkYhh/ http://jsfiddle.net/NkYhh/

You may try: 您可以尝试:

if(counter == 0) {

Edit: also you are declaring counter 3 times. 编辑:同样,您要声明计数器3次。

perhaps you meant this? 也许你是这个意思?

var toggle =0;

function toggleIt() { 
  toggle=!toggle;
  $(".two").toggleClass("two-menu",toggle);
  $(".four").toggleClass( "four-menu",toggle);
  $(".images").toggleClass( "images-menu",toggle);
  $(".home").toggleClass( "home-menu",toggle);

  $(".four").toggleClass( "bottom-left",!toggle );
  $(".four").toggleClass( "bottom-right",!toggle );
  $(".two").toggleClass( "margin-zero",!toggle );
}

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

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