18910140161

JavaScript-滚动时粘滞浮动DIV元素-堆栈溢出

顺晟科技

2022-10-18 13:52:07

96

我想做一个有粘性和浮动性的元素。基本上,这就像你在手机上播放YouTube视频一样。即使您向下滚动屏幕,视频也会一直在顶部播放。我试过这个姿势:粘,但不起作用。我怎么能这么做?先

谢谢了

<代码><;DIV Class=“ renungan-IMG-mobile feature-IMG ” style=“ position:sticky;”>;<;DIV onclick=this.nextelementsibling.style.display=' block ';this.style.display=' none '>;<;DIV类=“ image-wrapper ”>;<;IMG SRC=“ noimage.PNG ” style=“ cursor:pointer ”/>;<;IMG CLASS=“ play-button-renungan-mobile ” SRC=“ noimage.PNG ” alt=“ ” loading=“ lazy ”>;<;/DIV>;<;/DIV>;<;DIV Class=“ YouTube-video ” style=“ display:none ”>;<;iframe SRC=“ https://www.youtube.com/embed/xbxxgr_7eui ” title=“ YouTube视频播放器” frameborder=“ 0 ” allow="加速计;自动播放;剪贴板书写;加密媒体;陀螺仪;画中画允许全屏>;<;/iframe>;<;/DIV>;<;/DIV>;
enter image description here


顺晟科技:

你需要设定一个位置让它坚持下去。

<代码>正文{高度:4000px;}
<代码><;DIV Class=“ renungan-IMG-mobile feature-IMG ” style=" position:sticky;顶部:50px;>;<;DIV onclick=this.nextelementsibling.style.display=' block ';this.style.display=' none '>;<;DIV类=“ image-wrapper ”>;<;IMG SRC=“ noimage.PNG ” style=“ cursor:pointer ”/>;<;IMG CLASS=“ play-button-renungan-mobile ” SRC=“ noimage.PNG ” alt=“ ” loading=“ lazy ”>;<;/DIV>;<;/DIV>;<;DIV Class=“ YouTube-video ” style=“ display:none ”>;<;iframe SRC=“ https://www.youtube.com/embed/xbxxgr_7eui ” title=“ YouTube视频播放器” frameborder=“ 0 ” allow="加速计;自动播放;剪贴板书写;加密媒体;陀螺仪;画中画允许全屏>;<;/iframe>;<;/DIV>;<;/DIV>;

  • TAG:
相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航