简体   繁体   English

Position:修复了 Safari 与 Chrome 不同的处理方式

[英]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上的小提琴结果: Chrome上的小提琴结果

Fiddle result on Safari: 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.

相关问题 边距在软边缘Vs中呈现的方式有所不同。 Chrome / Safari - Margin is rendering differently in m'soft edge Vs. Chrome/ Safari 在Flexbox中固定的位置在Chrome和Safari / Firefox之间的行为有所不同 - Position fixed in Flexbox behaves differently between chrome and safari / firefox 文件路径在Safari和Chrome中的处理方式不同? - File path handled differently in Safari and Chrome? 谷歌网页字体在移动版 Safari 和桌面版 Chrome 上的呈现方式不同? - Google web font renders differently on mobile Safari vs. desktop Chrome? CSS定位Internet Explorer与Chrome / Firefox / Safari菜单位置。 尽我所能 - CSS positioning Internet Explorer vs. Chrome/Firefox/Safari menu position. Doing my head in Safari与Chrome的兼容性问题 - Safari vs. Chrome Compatibility Issues 固定位置在IE 10与Bootstrap Modal中的Chrome和Firefox之间表现不同 - Fixed position behaving different in IE 10 vs. Chrome and Firefox inside Bootstrap Modal 图像在 Chrome/Firefox 与 Safari 中的显示方式不同 - Images Showing Up Differently in Chrome/Firefox vs Safari JavaScript方法无法在Mobile Safari与Android Chrome中一致执行 - JavaScript Methods Not Executing Consistently In Mobile Safari vs. Android Chrome FF 3.5和3.0中的CSS“位置:固定”渲染 - CSS “position:fixed” rendering in FF 3.5 vs. 3.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM