jQuery:开关效果混乱

jQuery:开关效果混乱,jquery,css,switch-statement,Jquery,Css,Switch Statement,我有一些问题 .onoff开关低于1.on和.off,CSS不透明度中的off:0 我想得到的效果只有一个是开的,另一个是关的,并且可以开关on off 现在它很混乱,我不知道怎么做 请帮帮我 给你一个解决方案 $document.on'click',on.off',函数{ 如果!$this.hassclasssonoff{ $this.find'.on'.animate{marginLeft:'-=12px',不透明度:0},250 .next'.off'.animate{marginLef

我有一些问题

.onoff开关低于1.on和.off,CSS不透明度中的off:0

我想得到的效果只有一个是开的,另一个是关的,并且可以开关on off

现在它很混乱,我不知道怎么做

请帮帮我


给你一个解决方案

$document.on'click',on.off',函数{ 如果!$this.hassclasssonoff{ $this.find'.on'.animate{marginLeft:'-=12px',不透明度:0},250 .next'.off'.animate{marginLeft:'+=12px',不透明度:1},250; $this.addClassisonoff; }否则{ $this.find'.on'.animate{marginLeft:'+=12px',不透明度:1},250 .next'.off'.animate{marginLeft:'-=12px',不透明度:0},250; $this.removeClassisonoff; var index=$this.closest'.post'.index; $'.onoff'.eachfunction{ ifindex!=$this.closest.post.index{ $this.find'.on'.animate{marginLeft:'-=12px',不透明度:0},250 .next'.off'.animate{marginLeft:'+=12px',不透明度:1},250; $this.addClass'isonoff'; } }; }; }; .邮政{ 宽度:666px; 高度:111px; 大纲:无; 背景色:fff; 显示:块; 位置:相对位置; 溢出:隐藏; 文本对齐:开始; 边缘底部:20px; } 奥诺夫先生{ 光标:指针; 宽度:33px; 高度:33像素; 位置:绝对位置; 左:15px; 底部:15px; 背景:abcdef; } .在{ 宽度:33px; 高度:33像素; 位置:绝对位置; 顶部:0px; 光标:指针; 左:13px; 背景:abc456; } .关{ 宽度:33px; 高度:33像素; 位置:绝对位置; 左:0px; 不透明度:0; 顶部:0px; 光标:指针; 背景:defabc; } 视频1 在…上 关 视频2 在…上 关 视频3 在…上 关 视频4 在…上 关
干得好伙计butttt这不是我什么。。。。看这个很好,但是很慢,一个打开一个关闭需要点击两次,为什么?
$(document).on('click', '.onoff', function() {
  if ($(this).parents().siblings().find('.off').css("opacity") == "0") {
    $(this).parents().siblings()
      .find('.on').animate({marginLeft: '+=12px',opacity: 1},250)
      .next('.off').animate({marginLeft: '-=12px',opacity: 0}, 250);
  };

  if (!$(this).hasClass("isonoff")) {
    $(this).find('.on').animate({marginLeft: '-=12px',opacity: 0},250)
      .next('.off').animate({marginLeft: '+=12px',opacity: 1}, 250);
    $(this).addClass("isonoff");
  } else {
    $(this).find('.on').animate({marginLeft: '+=12px',opacity: 1},250)
      .next('.off').animate({marginLeft: '-=12px',opacity: 0}, 250);
    $(this).removeClass("isonoff");
  };
});