jquery - 具有 jQuery 宽度的 CSS 动画仍然可见 0%

标签 jquery html css animation

我正在尝试为不同的区域设置动画。 View 如下: 有5个区域: A、B、C、D 和 E。

其中 3 个可以一次可见。动画有效,但是当我隐藏必须为 0% 的 2 个区域时,仍然有一条可见的白线。

我尝试用 margin-left: -4px; 修复它,但我认为这不是正确的方法。

在我的示例中,当我关闭 margin-left 时,您可以看到白线。

    $('.EditJob').on('click', function(e) {
      $('.BNone').toggleClass('BGroot BNone');
      $('.CGroot').toggleClass('CKleiner CGroot');
      $('.EKlein').toggleClass('ENone EKlein');
      $('.ButtonHide').toggleClass('EditJobHide EditJob');
    });

    $('.CloseWorkItemPreview').on('click', function(e) {
      $('.BGroot').toggleClass('BNone BGroot');
      $('.CKleiner').toggleClass('CGroot CKleiner');
      $('.ENone').toggleClass('EKlein ENone');
      $('.ButtonHide').removeClass('EditJobHide');
    });

    $('.EditQueueItemPreview').on('click', function(e) {
      $('.AGroot').toggleClass('AKlein AGroot');
      $('.CGroot').toggleClass('CKlein CGroot');
      $('.DNone').toggleClass('DGroot DNone');
      $('.EKlein').toggleClass('ENone EKlein');
      $('.ButtonHide').toggleClass('EditJobHide EditJob');
    });

    $('.CloseQueueItemPreview').on('click', function(e) {
      $('.AKlein').toggleClass('AGroot AKlein');
      $('.CKlein').toggleClass('CGroot CKlein');
      $('.DGroot').toggleClass('DNone DGroot');
      $('.ENone').toggleClass('EKlein ENone');
      $('.ButtonHide').removeClass('EditJobHide');
    });
.AGroot {
  background-color: #90C3D4;
  display: inline-block;
  height: 960px;
  width: 25%;
  overflow: hidden;
  transition: 3s width linear;
  white-space: nowrap;
}
.AKlein {
  background-color: #90C3D4;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  transition: 3s width linear;
  white-space: nowrap;
}
.BGroot {
  background-color: #83CCC8;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.BNone {
  background-color: #83CCC8;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CGroot {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  //  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CKlein {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 25%;
  overflow: hidden;
  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CKleiner {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.DGroot {
  background-color: #CCC383;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.DNone {
  background-color: #CCC383;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.EKlein {
  background-color: #CCA983;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  //  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.ENone {
  background-color: #CCA983;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="AGroot">
  <div class="ButtonHide">
    <button class="EditJob">Edit</button>
  </div>
  Area: A
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>

</div>

<div class="BNone">
  <button class="CloseWorkItemPreview">Close</button>
  Area: B
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div>

<div class="CGroot">
  <div class="ButtonHide">
    <button class="EditQueueItemPreview">Edit</button>
  </div>
  Area: C
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div>

<div class="DNone">
  <button class="CloseQueueItemPreview">Close</button>
  Area: D
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div>

<div class="EKlein">
  Area: E
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>

</div>

JSFiddle

最佳答案

这是因为您使用的是 display: inline-block;,它会尊重元素之间的空白。

解决此问题的最简单方法是删除 html 中 div 之间的空格。

    $('.EditJob').on('click', function(e) {
      $('.BNone').toggleClass('BGroot BNone');
      $('.CGroot').toggleClass('CKleiner CGroot');
      $('.EKlein').toggleClass('ENone EKlein');
      $('.ButtonHide').toggleClass('EditJobHide EditJob');
    });

    $('.CloseWorkItemPreview').on('click', function(e) {
      $('.BGroot').toggleClass('BNone BGroot');
      $('.CKleiner').toggleClass('CGroot CKleiner');
      $('.ENone').toggleClass('EKlein ENone');
      $('.ButtonHide').removeClass('EditJobHide');
    });

    $('.EditQueueItemPreview').on('click', function(e) {
      $('.AGroot').toggleClass('AKlein AGroot');
      $('.CGroot').toggleClass('CKlein CGroot');
      $('.DNone').toggleClass('DGroot DNone');
      $('.EKlein').toggleClass('ENone EKlein');
      $('.ButtonHide').toggleClass('EditJobHide EditJob');
    });

    $('.CloseQueueItemPreview').on('click', function(e) {
      $('.AKlein').toggleClass('AGroot AKlein');
      $('.CKlein').toggleClass('CGroot CKlein');
      $('.DGroot').toggleClass('DNone DGroot');
      $('.ENone').toggleClass('EKlein ENone');
      $('.ButtonHide').removeClass('EditJobHide');
    });
.AGroot {
  background-color: #90C3D4;
  display: inline-block;
  height: 960px;
  width: 25%;
  overflow: hidden;
  transition: 3s width linear;
  white-space: nowrap;
}
.AKlein {
  background-color: #90C3D4;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  transition: 3s width linear;
  white-space: nowrap;
}
.BGroot {
  background-color: #83CCC8;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.BNone {
  background-color: #83CCC8;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CGroot {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  //  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CKlein {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 25%;
  overflow: hidden;
  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.CKleiner {
  background-color: #83CC89;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.DGroot {
  background-color: #CCC383;
  display: inline-block;
  height: 960px;
  width: 60%;
  overflow: hidden;
  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.DNone {
  background-color: #CCC383;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
.EKlein {
  background-color: #CCA983;
  display: inline-block;
  height: 960px;
  width: 15%;
  overflow: hidden;
  //  margin-left: -8px;
  transition: 3s width linear;
  white-space: nowrap;
}
.ENone {
  background-color: #CCA983;
  display: inline-block;
  height: 960px;
  width: 0%;
  overflow: hidden;
  //  margin-left: -4px;
  transition: 3s width linear;
  white-space: nowrap;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="AGroot">
  <div class="ButtonHide">
    <button class="EditJob">Edit</button>
  </div>
  Area: A
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>

</div><div class="BNone">
  <button class="CloseWorkItemPreview">Close</button>
  Area: B
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div><div class="CGroot">
  <div class="ButtonHide">
    <button class="EditQueueItemPreview">Edit</button>
  </div>
  Area: C
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div><div class="DNone">
  <button class="CloseQueueItemPreview">Close</button>
  Area: D
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>
</div><div class="EKlein">
  Area: E
  <p>
    This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
  </p>

</div>

JS Fiddle

关于jquery - 具有 jQuery 宽度的 CSS 动画仍然可见 0%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784276/

相关文章:

javascript - 基于html属性的动态jquery选择器

jquery - 是否可以只 overflow hidden 的文本而不 overflow hidden 的子绝对 div?

javascript - 使用 javaScript 在新窗口中插入带有一些谷歌地图内容的代码

javascript - 当select有值时在select by text中选择值?

jquery - 如果没有更多图片,则禁用(下一个/上一个)按钮

javascript - 当我调整页面大小时,我的菜单和标题移动,我做错了什么?

javascript - JQuery.css ("display") = "block"不工作

javascript - 使 Jquery 代码仅在元素在屏幕上时运行

javascript - 通过 CSS 和 javascript 绘制树和动态设计(模式)

css - Umbraco - Fanoe 初学者工具包 - 如何在所有屏幕尺寸上显示 "hamburger"菜单而不是导航?