gpt4 book ai didi

javascript - addClass()/removeClass() 转换导致 Safari 中瞬间位置跳转?

转载 作者:行者123 更新时间:2023-12-01 05:16:09 25 4
gpt4 key购买 nike

什么会导致 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 特有的问题。

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

这是我正在使用的 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;
}

对此有何意见?

最佳答案

我在这里标记了类似问题的答案:https://stackoverflow.com/a/49101640/9214076 。另外,我已经应用了这个答案,并在这里更新了原始问题:How to Make a Fixed Element Stay Relative to the Current Top Scroll Position? .

关于javascript - addClass()/removeClass() 转换导致 Safari 中瞬间位置跳转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49079479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com