我有一个页面,该页面具有不可见的(不透明度= 0),并且基于 istertersectectect
属性,因为用户向下滚动不透明度变化为1。它非常简单,并且是对互隔板的基本实现。
但是,我在Safari支持方面遇到了一些问题,也许像我这样的其他人正在使用较旧的浏览器。因此,我在下面的JS文件中使用了功能检测
if ("IntersectionObserver" in window){
// Javascript here
}
,这对于更早工作的浏览器来说正常工作。但是,我的CSS仍然具有不透明度为0,我需要向那些不支持IntersectionObserver的浏览器展示该内容为1。
我该怎么做?
,换句话说,有什么方法可以在CSS中应用条件,即使有的话,我该如何将JS变量放入CSS?
是否会不胜感激。
I have a page which has the content invisible (opacity = 0) and based on the isIntersecting
property as the user scrolls down the opacity changes to 1. It's pretty simple and a basic implementation of the IntersectionObserver API.
However I was having some issue with Safari support and maybe there are others like me who are using older browsers. So I used feature detection in the JS file as below
if ("IntersectionObserver" in window){
// Javascript here
}
And this works fine for the browsers where it was working even earlier. However my CSS still has the opacity as 0 and I need to show that content with opacity as 1 to those browsers who don't support IntersectionObserver..
How do I do this?
In other words, is there a way where I can apply conditions in CSS and even if there is, then how do I take a JS variable into CSS?
Any advise would be appreciated.
发布评论
评论(2)
交叉点观察者不支持iOS 12下方,因此对于较旧的版本,您可以使用,然后无需更改其他CSS或其他任何内容。
Intersection Observer isn't supported below iOS 12, so for the older versions you can use https://www.npmjs.com/package/intersection-observer, and then no need for additional CSS changing or anything.
您可以使用CSS变量设置不透明度并在JS中更改该不透明度。
You could set the opacity using a CSS variable and change that in the JS.