Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

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

Packages

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.

Behavior

Save Automatically?

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.

HTML

              
                <div class="container">
    <div class="nav">
        <ul>
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="p01"></div>
    <div class="p02"></div>
    <div class="p03"></div>
    <div class="p04"></div>
    <div class="p05"></div>
</div>
<div class="gotop">
    <i class="fa fa-arrow-circle-up fa-2x"></i>
</div>
              
            
!

CSS

              
                *{
    padding: 0;
    margin: 0;
}

body{
    overflow: hidden;
}
/*插入導覽列*/
.nav{
    position: fixed;
    top: 50%;
    right: 0;
}
.nav ul li{
    width: 10px;
    height: 10px;
    margin: 10px;
    background-color: #fff;
    box-shadow: 1px 1px 1px rgba(0,0,0,0.5) inset;
    cursor: pointer;
}
.nav ul .active{
    background-color: #43A55F;
}

/*每頁顯示的圖片*/
.p01{
    background-image: url(http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/images/p01.jpg);
    background-size: cover;
    height: 100vh;
}
.p02{
    background-image: url(http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/images/p02.jpg);
    background-size: cover;
    height: 100vh;
}
.p03{
    background-image: url(http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/images/p03.jpg);
    background-size: cover;
    height: 100vh;
}
.p04{
    background-image: url(http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/images/p04.jpg);
    background-size: cover;
    height: 100vh;
}
.p05{
    background-image: url(http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/images/p05.jpg);
    background-size: cover;
    height: 100vh;
}
.gotop{
    color: rgba(226, 248, 156, 0.9);
    position: fixed;
    bottom: 20px;
    right: 20px;
    cursor: pointer;
}
              
            
!

JS

              
                $(document).ready(function() {

    var num_li = $(".nav li").length;
    
    var n = 1;
    var moving = 0;
    $(window).mousewheel(function(e) {
        $("html, body").stop();
        if (moving == 0) {
            moving = 1;
            if (e.deltaY == -1) {
                if (n < num_li) {
                    n++;
                }
            } else {
                if (n > 1) {
                    n--;
                }
            }
        }
        console.log(n);
        $("html, body").animate({
            "scrollTop": $(".p0" + n).offset().top
        }, function(){
            moving = 0;
        })
    })

    //  點選右方導覽列時會到指定圖片
    for (var i = 0; i <= num_li; i++) {
        $(".nav li:eq(" + i + ")").click({
            id: i
        }, function(e) {
            $(".nav li").css("background-color", "#FFF");
            var page = e.data.id + 1;
            $("html,body").animate({
                "scrollTop": $(".p0" + page).offset().top
            })
            $(this).css("background-color", "#43a55f");
            n = e.data.id +1
        })
    }

    //  一進入網頁時,將導覽列垂直置中
    center();

    //  縮放網頁時,重新將導覽列置中
    $(window).resize(function() {
        center();
    })

    //  計算導覽列垂直置中的高度
    function center() {
        var pos = $(window).height() / 2 - $(".nav").height() / 2;
        $(".nav").css("top", pos);
    }
    $(window).scroll(function() {
        if ($(window).scrollTop() >= $(".p01").offset().top && $(window).scrollTop() < $(".p02").offset().top) {
            $(".nav li").css("background-color", "white") //除了被點擊到的游標,其他都恢復成原來的顏色
            $(".nav li:eq(0)").css("background-color", "#46dd46")
        } else if ($(window).scrollTop() >= $(".p02").offset().top && $(window).scrollTop() < $(".p03").offset().top) {
            $(".nav li").css("background-color", "white") //除了被點擊到的游標,其他都恢復成原來的顏色
            $(".nav li:eq(1)").css("background-color", "#46dd46")
        } else if ($(window).scrollTop() >= $(".p03").offset().top && $(window).scrollTop() < $(".p04").offset().top) {
            $(".nav li").css("background-color", "white") //除了被點擊到的游標,其他都恢復成原來的顏色
            $(".nav li:eq(2)").css("background-color", "#46dd46")
        } else if ($(window).scrollTop() >= $(".p04").offset().top && $(window).scrollTop() < $(".p05").offset().top) {
            $(".nav li").css("background-color", "white") //除了被點擊到的游標,其他都恢復成原來的顏色
            $(".nav li:eq(3)").css("background-color", "#46dd46")
        } else if ($(window).scrollTop() >= $(".p05").offset().top) {
            $(".nav li").css("background-color", "white") //除了被點擊到的游標,其他都恢復成原來的顏色
            $(".nav li:eq(4)").css("background-color", "#46dd46")
        }
    })
    
    //  點擊 gotop 時回到頂端
    $(".gotop").click(function(){
        $("html,body").animate({"scrollTop":"0"})
        n = 1;
    })
    
    //  離開頁頂時才出現 gotop 按扭
    $(".gotop").fadeOut(0);
    $(window).scroll(function(){
        if($(window).scrollTop() >= $(".p02").offset().top){
            $(".gotop").fadeIn();
        }else{
            $(".gotop").fadeOut();
        }
    });
})
              
            
!
999px

Console