[英]Position: fixed handled differently by Safari vs. Chrome
I have a React app in which, after you scroll past a shopping cart, it becomes fixed to stay in view.我有一个 React 应用程序,在您滚动购物车后,它会固定在视图中。
In Chrome, upon becoming fixed, the cart needs a transform: translateX(-100%)
to retain its X-position.在 Chrome 中,在固定后,购物车需要
transform: translateX(-100%)
以保留其 X 位置。 In Safari, it doesn't, and applying the rule causes the cart to misalign.在 Safari 中,它没有,并且应用该规则会导致购物车错位。
A stripped example can be seen here: https://jsfiddle.net/du167r85/ -- the cart becomes fixed after 1 second.可以在这里看到一个剥离的示例: https://jsfiddle.net/du167r85/ - 购物车在 1 秒后固定。
Fiddle result on Chrome: Chrome上的小提琴结果:
Fiddle result on Safari: Safari 上的小提琴结果:
If the element is fixed from the start (eg without a timer or scroll event), Safari and Chrome render it the same, both requiring the transform: translateX(-100%)
rule.如果元素从一开始就固定(例如,没有计时器或滚动事件),Safari 和 Chrome 呈现相同,都需要
transform: translateX(-100%)
规则。
Is this a bug, and there a workaround for this issue?这是一个错误,并且有解决此问题的方法吗?
I guess one of your problems is that you haven't defined a position left or right for your fixed element.我想你的问题之一是你没有为你的固定元素定义一个 position 左或右。
Give right: 60px;
给
right: 60px;
to your #cart
and comment -webkit-transform: translateX(-100%);
到您的
#cart
并评论-webkit-transform: translateX(-100%);
Here's and updated JSFiddle这是和更新的JSFiddle
Tested both on Safari and Chrome and it's working fine.在 Safari 和 Chrome 上都进行了测试,并且工作正常。
Another thing I would do is to move the position: fixed;
我要做的另一件事是移动
position: fixed;
up to #cart-wrap
.最多
#cart-wrap
。 I tried it as well and it still works fine!我也试过了,它仍然可以正常工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.