css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  each val in [701, 702, 703, 704, 705]
      img(src= 'https://picsum.photos/600/300?image='+val)

    position: relative
    max-width: 600px
        position: absolute
        top: 0
        left: 0
        display: block
        width: 100%
        opacity: 0
        visibility: hidden
        transition: .8s
            position: static
            opacity: 1
            visibility: visible
    .prev, .next
        display: block
        position: absolute
        top: 50%
        transform: translateY(-50%)
        cursor: pointer
        transition: .4s
        background-color: rgba(0,0,0,.12)
        padding: 14px 12px
            background-color: rgba(0,0,0,.24)
            display: block
            content: ""
            width: 10px
            height: 10px
            border-top: 2px solid #fff
            border-right: 2px solid #fff
        left: 0
            transform: rotate(-135deg)
            margin-left: 4px
        right: 0
            transform: rotate(45deg)
            margin-right: 4px
              var counter = 0, // 一開始要顯示的圖,0 的話就是顯示第一張
    slide = document.querySelector('#slide'),
    items = slide.querySelectorAll('img'), // 抓取所有 img
    itemsCount = items.length, // 圖片總數 
    prevBtn = document.createElement('a'), // 上一張按鈕
    nextBtn = document.createElement('a'), // 下一張按鈕
    timer = 4000, // 4 秒換圖
    interval = window.setInterval(showNext, timer);  // 設定循環

prevBtn.classList.add('prev'); // 幫上一張按鈕加 class="prev" 給 CSS 指定樣式用
nextBtn.classList.add('next'); // 幫下一張按鈕加 class="next" 給 CSS 指定樣式用
slide.appendChild(prevBtn); // 將按鈕加到 #slide 裡

// 帶入目前要顯示第幾張圖 
var showCurrent = function(){
  	var itemToShow = Math.abs(counter % itemsCount); // 取餘數才能無限循環
  	[].forEach.call( items, function(el){
    	el.classList.remove('show'); // 將所有 img 的 class="show" 移除
  	items[itemToShow].classList.add('show'); // 將要顯示的 img 加入 class="show"

function showNext(){
	counter++; // 將 counter+1 指定下一張圖

function showPrev(){
	counter--; // 將 counter-1 指定上一張圖

// 滑鼠移到 #slider 上方時,停止循環計時
slide.addEventListener('mouseover', function(){
	interval = clearInterval(interval);

// 滑鼠離開 #slider 時,重新開始循環計時
slide.addEventListener('mouseout', function(){
	interval = window.setInterval(showNext, timer);

// 綁定點擊上一張,下一張按鈕的事件
nextBtn.addEventListener('click', showNext, false);
prevBtn.addEventListener('click', showPrev, false);

// 一開始秀出第一張圖,也可以在 HTML 的第一個 img 裡加上 class="show"
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................