适用浏览器:360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗. 不支持IE8及以下浏览器。
来源:站长素材
npm install sticky-js
bower install sticky.js
Simply include
<script src="sticky.min.js"></script>
Then have element
<div class="selector">Sticky element</div>
Initialize with javascript
var sticky = new Sticky('.selector');
CommonJS
var Sticky = require('sticky-js');
var sticky = new Sticky('.selector');
Sticky to the nearest parent container with [data-sticky-container]
<div data-sticky-container>
<div class="selector">Sticky element</div>
</div>