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 id="all">
    <div class="nav">
        <ul>
            <li class="active">無名小物</li>
            <li>高 CP 值人氣機王</li>
            <li>秋葉原 3C</li>
        </ul>
    </div>
    <div class="banner">
        <img src="http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/yahoo/banner1.jpg" alt="" />
        <img src="http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/yahoo/banner2.jpg" alt="" />
        <img src="http://www.pjchender.com/pjchender_blog/MaCloud_jQuery/yahoo/banner3.jpg" alt="" />
    </div>
</div>
              
            
!

CSS

              
                * {
    margin: 0;
    padding: 0;
}

#all {
    width: 949px;
    height: 424px;
    margin: auto;
    overflow: hidden;
}

.nav {
    width: 949px;
    height: 40px;
    margin-bottom: 10px;
    margin-top: 20px;
    border-bottom: 1px solid #07A1D4;
    padding-bottom: 3px
}

.nav li {
    float: left;
    list-style-type: none;
    color: darkgray;
    font-family: 微軟正黑體;
    width: 150px;
    font-size: 16px;
    text-align: center;
    line-height: 40px;
    cursor: pointer
}

.nav .active {
    font-weight: bold;
    color: #0785d4;
    font-size: 21px;
    border-bottom: 4px solid #07A1D4;
}

.banner {
    height: 354px;
    position: relative
}

.banner img {
    float: left
}
              
            
!

JS

              
                $(document).ready(function() {
    var num_li = $(".nav li").length;
    var img_width = 949;
    var width_banner = num_li*img_width;
    var timer = 3000; //  設定輪撥速度
    $(".banner").css("width", width_banner);

    //  當滑鼠移過時,圖片移動到特定位置
    for (i = 0; i < num_li; i++) {
        $(".nav li:eq(" + i + ")").mouseenter({
            id: i
        }, function(e) {
            n = e.data.id
            change();
        })
    }

    //  設定輪撥函數
    clock = setInterval(auto, timer);
    n = 0;

    function auto() {
        n++;
        if (n >= num_li) {
            n = 0;
        }
        position = -n * img_width;
        $(".banner").animate({
            "left": +position + "px"
        }, 400)

        $(".nav li").css({
                "font-weight": "none",
                "color": "darkgray",
                "font-size": "16px",
                "border-bottom": "none"
            })
            //  讓滑鼠移到的清單改變成 hover 字體
        $(".nav li:eq(" + n + ")").css({
            "font-weight": "bold",
            "color": "#0785d4",
            "font-size": "18px",
            "border-bottom": "4px solid #07A1D4"
        })
    }

    //  當滑鼠移到圖案上時輪撥暫停
    $(".banner img").hover(function() {
        clearInterval(clock)
    }, function() {
        clock = setInterval(auto, timer)
    })

    //  當滑鼠移到 nav 時,根據標題移動圖片
    function change() {
        clearInterval(clock);
        clock = setInterval(auto, timer);
        position2 = -n * img_width;
        $(".banner").stop();
        $(".banner").animate({
                "left": +position2 + "px"
            }, 400)
            //  讓所有的清單變回原本的字體
        $(".nav li").css({
                "font-weight": "none",
                "color": "darkgray",
                "font-size": "16px",
                "border-bottom": "none"
            })
            //  讓滑鼠移到的清單改變成 hover 字體
        $(".nav li:eq(" + n + ")").css({
            "font-weight": "bold",
            "color": "#0785d4",
            "font-size": "18px",
            "border-bottom": "4px solid #07A1D4"
        })
    }
})
              
            
!
999px

Console