addClass()/removeClass() 转换导致 Safari 中的分秒位置跳转?

addClass()/removeClass() Transition Causes Split-Second Position Jump in Safari?

什么会导致 addClass()/removeClass() 属性破坏流畅的过渡?

这是我正在使用的当前脚本:

$(document).ready(function() {
  var o = 0;
  $("a.lbimg > img.lb-click").click(function() {
    var s = $("body");
    o = $(window).scrollTop(), s.css("position", "fixed"), s.css("top", "-" + o + "px"), s.css("background-position", "0 -" + o + "px"), s.addClass("no-scroll"), $("#lb-view").addClass("target");
  }), $("#lb-controls").on("click", function() {
    var s = $("body");
    s.css("position", ""), s.css("background-position", ""), o = $(window).scrollTop(o), s.removeClass("no-scroll"), $("#lb-view").removeClass("target");
  });
});

有点难解释;但是,这似乎是 Safari 特有的问题。

这是主要问题:单击照片时,它会在灯箱中打开图像 window。然后,在关闭 window 时,body 位置 jumps/shifts 仅一瞬间就会调整回当前 window 滚动位置。从本质上讲,它破坏了函数的可见流动性。

这是我正在使用的 CSS 类型的片段:

body,
html {
  height: 100%;
  width: 100%;
  background-size: cover;
  background-repeat: no-repeat;
}

body {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  z-index: -7;
}

body.no-scroll {
  overflow: hidden;
  width: 100%;
  height: auto;
}

img {
  z-index: 1;
}

a.lbimg {
  cursor: pointer;
  display: block;
  line-height: 0;
}

a.lbimg img {
  margin: 0 auto;
  padding: 0;
  border: 0;
}

.lb-click {
  height: auto;
}

.customlightbox {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  opacity: 0;
  position: fixed;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.7);
  z-index: -8;
}

.lbimg-wrap {
  width: 100%;
  height: 100%;
  position: relative;
  padding: 45px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-align: center;
}

.customlightbox img {
  position: relative;
  width: auto;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  top: 50%;
  opacity: 0;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}

#lb-controls {
  position: fixed;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  height: 50px;
  width: 50px;
  top: -50px;
  opacity: .7;
  cursor: pointer;
  z-index: 5;
}

#lb-close {
  display: block;
  position: absolute;
  overflow: hidden;
  height: 30px;
  width: 30px;
  right: 10px;
  top: 10px;
  -webkit-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  transform: rotate(45deg);
}

#lb-close:before,
#lb-close:after {
  content: '';
  display: block;
  position: absolute;
  background: white;
  -webkit-border-radius: 2px;
  -moz-border-radius: 2px;
  border-radius: 2px;
}

#lb-close:before {
  width: 2px;
  height: 0;
  top: 0;
  left: 14px;
}

#lb-close:after {
  width: 0;
  height: 2px;
  top: 14px;
  left: 0;
}

.customlightbox.target {
  display: inline-block;
  z-index: 4;
}

.customlightbox.target,
.customlightbox.target img {
  opacity: 1;
}

.customlightbox.target~#lb-controls {
  top: -3px;
}

.customlightbox.target~#lb-controls #lb-close:after {
  width: 30px;
}

.customlightbox.target~#lb-controls #lb-close:before {
  height: 30px;
}

.lb-animate {
  -webkit-transition: 0.5s ease-in-out;
  -o-transition: 0.5s ease-in-out;
  transition: 0.5s ease-in-out;
}

对此有任何意见吗?

我在这里标记了一个类似问题的答案:. Also, I've applied this answer, and updated the original question here: