Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div style="height: 200px; background: #999"></div>

<!-- 固定元素悬浮后,原来所在的位置会被空缺(height变成0),
 导致页面闪跳且计算不准,所以必须设置一个确定高度的div框住 -->
<div style="height:300px;">
    <div class="fixed" style="height: 300px; background: green; text-align: center;">滚动悬浮块</div>

<div style="height:400px;background: #999"></div>
<div class="bottom" style="height: 500px; background: red; text-align: center;">结束滚动块</div>
<div style="height:800px; background: #999"></div>




                $(function() {
    var fix = $('.fixed');                      //滚动悬浮块
    var end = $('.bottom');                     //滚动到这个元素后结束固定
    var fixTop = fix.offset().top,              //滚动悬浮块与顶部的距离
        fixHeight = fix.height();               //滚动悬浮块高度
    var endTop, miss;                           //结束元素与顶部的距离

    $(window).scroll(function() {
        var docTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);

        if (end.length > 0) {
            endTop = end.offset().top;
            miss = endTop - docTop - fixHeight;

        if (fixTop < docTop) {
            fix.css({'position': 'fixed'});
            if ((end.length > 0) && (endTop < (docTop + fixHeight))) {
                fix.css({top: miss});           //滚动悬浮块滑到结束块上时,top值为负,即慢慢隐藏出浏览器
            } else{
                fix.css({top: 0});              //滚动悬浮块未到结束块上时,top为0
        } else {
            fix.css({'position': 'static'});