[英]How would you implement code highlighting on scroll?
I'm looking to create a blog page similar to stripes documentation.我正在寻找一个类似于条纹文档的博客页面。 When the user scrolls the page, I would like to trigger different highlights on the code.
当用户滚动页面时,我想在代码上触发不同的亮点。 Check out stripes documentation here and see that the code gets highlighted based on the content when you scroll.
在此处查看条带文档,并查看代码在滚动时根据内容突出显示。 Is there a library that does this already, or what is the best approach to tackle this myself?
是否有一个图书馆已经这样做了,或者自己解决这个问题的最佳方法是什么?
It's basically a combination of a sticky element (the code container) and linking the scroll position with css styles using JavaScript.它基本上是一个粘性元素(代码容器)的组合,并使用 Z6036155AF75AEF07 将滚动 position 与 css styles 链接起来
Here you can find more information and a nice demo for such purposes: Scroll and let content stick while animating在这里,您可以找到更多信息和一个很好的演示用于此类目的: Scroll and let content stick while animating
To sum it all up, the mechanism of how it works is really just:
1. A scrolling container
2. position: sticky;elements
3. JavaScript that converts scroll position of the scrolling container to styles for sticky elements
4. (Sometimes) CSS transition property
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.