【Memo】可嵌入邊欄&內文的幻燈片語法

最近調整了一下部落格邊欄的刊品販售連結,把原本一長串的書單改成用幻燈片輪播呈現,讓邊欄顯得比較簡潔一點,像John子:


至於這種邊欄幻燈片要怎麼用出來哩,這邊就來PO一下使用說明:

首先,到這個部落格,把他第一個框框裡的程式碼通通複製下來,改掉他程式碼裡面預設的圖片網址和連結網址,再貼到你自己的部落格或網頁裡面,就大功告成。

至於如果看無英文,或不大確定要怎麼改的話,以下是我流版說明:

<!-- SLIDER CSS -->
<style type="text/css">
/*
 * jQuery FlexSlider v2.2.0
 * http://www.woothemes.com/flexslider/
 *
 * Copyright 2012 WooThemes
 * Free to use under the GPLv2 license.
 * http://www.gnu.org/licenses/gpl-2.0.html
 *
 * Contributing author: Tyler Smith (@mbmufffin)
 */


/* Browser Resets
*********************************/
.flex-container a:active,
.flexslider a:active,
.flex-container a:focus,
.flexslider a:focus  {outline: none;}
.slides,
.flex-control-nav,
.flex-direction-nav {margin: 0; padding: 0; list-style: none;}


/* FlexSlider Necessary Styles
*********************************/
.flexslider li {
border: 0 none !important;
padding: 0 !important;
text-indent: 0 !important;
margin-bottom: 0 !important;
}
.flexslider {margin: 0; padding: 0;}
.flexslider .slides > li {display: none; -webkit-backface-visibility: hidden;} /* Hide the slides before the JS is loaded. Avoids image jumping */
.flexslider .slides img {width: 100%; display: block;}
.flexslider .slides, .flexslider .slides img, .flex-direction-nav { margin: 0 !important; padding: 0 !important; }
.flex-pauseplay span {text-transform: capitalize;}

/* Clearfix for the .slides element */
.slides:after {content: "\0020"; display: block; clear: both; visibility: hidden; line-height: 0; height: 0;}
html[xmlns] .slides {display: block;}
* html .slides {height: 1%;}

/* No JavaScript Fallback */
/* If you are not using another script, such as Modernizr, make sure you
 * include js that eliminates this class on page load */
.no-js .slides > li:first-child {display: block;}

/* FlexSlider Default Theme
*********************************/
.flexslider { margin: 0 0 60px; background: #fff; border: 4px solid #fff; position: relative; -webkit-border-radius: 4px; -moz-border-radius: 4px; -o-border-radius: 4px; border-radius: 4px; -webkit-box-shadow: 0 1px 4px rgba(0,0,0,.2); -moz-box-shadow: 0 1px 4px rgba(0,0,0,.2); -o-box-shadow: 0 1px 4px rgba(0,0,0,.2); box-shadow: 0 1px 4px rgba(0,0,0,.2); zoom: 1; }
.flex-viewport { max-height: 2000px; -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -o-transition: all 1s ease; transition: all 1s ease; }
.loading .flex-viewport { max-height: 300px; }
.flexslider .slides { zoom: 1; }
.carousel li { margin-right: 5px; }

/* Direction Nav */
.flex-direction-nav {*height: 0;}
.flex-direction-nav a  { text-decoration:none; display: block; width: 40px; height: 45px; margin: -20px 0 0; position: absolute; top: 50%; z-index: 10; overflow: hidden; opacity: 0; cursor: pointer; color: rgba(0,0,0,0.8); text-shadow: 1px 1px 0 rgba(255,255,255,0.3); -webkit-transition: all .3s ease; -moz-transition: all .3s ease; transition: all .3s ease; }
.flex-direction-nav .flex-prev { background: url("http://project.dimpost.com/flexslider-basic/img/arrows1.png") no-repeat scroll -15px -92px transparent; left: -50px; }
.flex-direction-nav .flex-next { background: url("http://project.dimpost.com/flexslider-basic/img/arrows1.png") no-repeat scroll -15px -15px transparent; right: -50px; text-align: right; }
.flexslider:hover .flex-prev { opacity: 0.5; left: 10px; }
.flexslider:hover .flex-next { opacity: 0.5; right: 10px; }
.flexslider:hover .flex-next:hover, .flexslider:hover .flex-prev:hover { opacity: 0.9; }


/* Pause/Play */
.flex-pauseplay a { display: block; width: 20px; height: 20px; position: absolute; bottom: 5px; left: 10px; opacity: 0.8; z-index: 10; overflow: hidden; cursor: pointer; color: #000; }
.flex-pauseplay a:before  { font-family: "flexslider-icon"; font-size: 20px; display: inline-block; content: '\f004'; }
.flex-pauseplay a:hover  { opacity: 1; }
.flex-pauseplay a.flex-play:before { content: '\f003'; }

/* Control Nav */
.flex-control-nav {width: 100%; position: absolute; bottom: -40px; text-align: center;}
.flex-control-nav li {margin: 0 6px; display: inline-block; zoom: 1; *display: inline;}
.flex-control-paging li a {width: 11px; height: 11px; display: block; background: #666; background: rgba(0,0,0,0.5); cursor: pointer; text-indent: -9999px; -webkit-border-radius: 20px; -moz-border-radius: 20px; -o-border-radius: 20px; border-radius: 20px; -webkit-box-shadow: inset 0 0 3px rgba(0,0,0,0.3); -moz-box-shadow: inset 0 0 3px rgba(0,0,0,0.3); -o-box-shadow: inset 0 0 3px rgba(0,0,0,0.3); box-shadow: inset 0 0 3px rgba(0,0,0,0.3); }
.flex-control-paging li a:hover { background: #333; background: rgba(0,0,0,0.7); }
.flex-control-paging li a.flex-active { background: #000; background: rgba(0,0,0,0.9); cursor: default; }

.flex-control-thumbs {margin: 5px 0 0; position: static; overflow: hidden;}
.flex-control-thumbs li {width: 25%; float: left; margin: 0;}
.flex-control-thumbs img {width: 100%; display: block; opacity: .7; cursor: pointer;}
.flex-control-thumbs img:hover {opacity: 1;}
.flex-control-thumbs .flex-active {opacity: 1; cursor: default;}

@media screen and (max-width: 860px) {
  .flex-direction-nav .flex-prev { opacity: 1; left: 10px;}
  .flex-direction-nav .flex-next { opacity: 1; right: 10px;}
}
</style>
    
<!-- SLIDER HTML -->
      <div id="flex-isfb">
        <!-- Preloader -->
        <div id="preloader"></div>
        <style>
        /* Preloader */
        #preloader {
            position: absolute;
            top:0;
            left:0;
            right:0;
            bottom:0;
            background-color:#fff; /* change if the mask should have another color then white */
            z-index:999999999999; /* makes sure it stays on top */
        }
        
        </style>
        <div class="flexslider">
          <ul class="slides">
            <li>
                <a href="連結網址">
                <img src="圖片網址">
                </a>
            </li>
            <li>
                <a href="連結網址">
                <img src="圖片網址" />
                </a>
            </li>
            <li>
                <a href="連結網址">
                <img src="圖片網址" />
                </a>
            </li>
          </ul>
        </div>
      </div>

<!-- SLIDER JS -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://project.dimpost.com/flexslider-basic/js/jquery.flexslider-min.js"></script>
  <script type="text/javascript">
    $(window).load(function(){
      $('.flexslider').flexslider({
  animation: "slide",
  controlNav: true, 
  directionNav: true,
  easing: "swing",
  slideshowSpeed: 3000,        
     animationSpeed: 600, 
      });
    });
    //<![CDATA[
        $(window).load(function() { 
            $('#preloader').delay(350).fadeOut('slow'); 
        })
    //]]>
</script> 

首先,把上列程式碼複製起來,貼到你需要嵌入幻燈片的地方,Ctrl+F找到「圖片網址」「連結網址」,將它們用你想連的網址取代,至於圖片網址這個要上傳到你自己的可外連空間這個大家應該懂,就不多加說明了。

程式碼當中預設是三組圖片&網址連結,如果想增加的話就複製上列藍色的部分再貼上,依此類推,如果你只想放圖片,不想讓圖片有連結,直接將<a href="連結網址"></a>這兩個刪掉就好。

至於桃紅色的部分,則是這個幻燈片語法所使用的JavaScript,基本上上列的程式碼都是要呼叫這兩個JS才能起作用,而這兩個JS你可以從網址看到它是放在另外的空間裡,當然,目前看來這個空間是可以提供我們外連的,可是如果哪天他爆掉了還是怎樣,我們的幻燈片就會死掉了,所以審慎起見,我們可以把這兩隻JS抓下來,另外上傳到自己的空間裡,這樣就不用擔驚受怕惹!

  • jquery.min.js
  • jquery.flexslider-min.js

  • 將這兩隻JS下載回來之後,上傳到你自己的可外連空間中,例如Google Drive、Dropbox或One Drive之類,至於怎麼找到各空間的外連網址這個你自己研究BJ4,將你剛剛上傳好的JS網址取代原本的那兩隻JS網址(記得注意一下檔名,不要取代錯了),OK!大功告成!


    這邊提一下幻燈片語法的部分修正細節:

    ▶ animation: "slide",
    ▶ controlNav: true,
    ▶ directionNav: true,
    ▶ easing: "swing",
    ▶ slideshowSpeed: 3000,
    ▶ animationSpeed: 600,

    這幾個地方都可以隨你喜好改,但大部分不是很重要(喂),就是一些預設幻燈片要自己自動跑還是要人點他才會去跑之類的,以及幻燈片切換時的動畫樣式(這個要自己去查對應的樣式呼叫詞才行),有執念再去研究就好,你可能會比較需要改到的是slideshowSpeedanimationSpeed這兩個數值,slideshowSpeed是幻燈片單一圖片停留的時間,animationSpeed則是動畫切換的持續時間,這邊預設的slideshowSpeed是3000,就是3秒,所以如果你要改成4秒5秒6秒的話就依此類推。

    最後放上本文所使用的實用語法&工具出處:

    Image Slider For Blogger
    └ 這裡有各種炫砲的幻燈片語法,雖然他上面寫for Blogger,但一般網頁或可插入HTML/JS的部落格應該都能用。

    FORMAT MY SOURCE CODE FOR BLOGGING
    └ 可在網誌內文插入程式碼的線上轉換小程式,完全免安裝。

    留言

    1. 請問貼語法後IE沒辦法正昂常顯示

      回覆刪除
      回覆
      1. 這個語法IE不能用喔,因為IE跟jQuery好像有仇似的不給顯示就是不給,我已經放棄跟他纏鬥了(趴),如果堅持用IE的話建議還是找其他方法QQ

        刪除
    2. 情問圖片要怎麼條大小

      回覆刪除
      回覆
      1. 我是本來就用小張的圖片來連,要把每張圖片都調成同樣大小的話請自行用photoshop之類的軟體用喔

        刪除
    3. 情問外框要怎麼縮小

      回覆刪除
      回覆
      1. 我不知道欸,我是直接複製原語法,放在自己邊欄看起來OK就OK了,我沒有去調整外框大小

        刪除

    張貼留言

    ★ Blogger有時會誤把真人留言當成廣告擋掉,過很久我才會發現有留言,建議登入再留言比較不會被擋(つд⊂)

    ★ 因為Blogger擋太兇,所以現在設成只有兩週前的文章才會審核留言,新文章沒有審核制,先試營運一陣子看看,歡淫大家留言~ヽ(゚∀。)ノ

    隨機文章(踩雷區)