星期六, 2月 22, 2014

[jQuery Plugins] 影片在bootstrap carousel中時,當影片播放時如何停止carousel

很多網站的banner都會使用bootstrap carousel這個外掛
當使用者點擊carousel的影片播放時,需要暫停carousel自動換頁的動作。

目前影片是採用Vimeo,所以你可以使用Froogaloop這個元件來取得Vimeo的控制。
完整範例可參考:http://developer.vimeo.com/player/js-api

一開始在用的時候,沒有認真看文件的說明,導致AddEvent的事件完全無動作,大家要注意嵌入的影片格式要包含api=1與player_id=


相關範例如下:

        var $myCarousel = $("#carousel-iangel");
        $myCarousel.on("slide.bs.carousel", function(event) {
            $.console("change slide");
            var $currentSlide = $myCarousel.find(".active iframe");
            // exit if there"s no iframe, i.e. if this is just an image and not a video player
            if (!$currentSlide.length) { return; }
            
            // pass that iframe into Froogaloop, and call api("pause") on it.
            var player = Froogaloop($currentSlide[0]);
            player.api("pause");
        });

        
        var iframe = $("#videoIntro")[0],
            player = $f(iframe); //$f 這是Froogaloop提供的方法

        // When the player is ready, add listeners for pause, finish, and playProgress
        player.addEvent("ready", function() {
            player.addEvent("play", function(id) {
                // $.console("id:" + id + " play");
                $myCarousel.carousel("pause");
            });
            player.addEvent("pause", function(id) {
                // $.console("id:" + id + " pause");
                $myCarousel.carousel("pause");
            });
            player.addEvent("finish", function(id) {
                // $.console("id:" + id + " finish");
                $myCarousel.carousel("cycle");
            });
            player.addEvent("loadProgress", function(data, id) {
                // $.console(data.seconds + "s played");
            });
        });

星期一, 2月 17, 2014

[VIM] 如何做全選+複製

常常會用的VIM指令
Reference:
http://stackoverflow.com/questions/1620018/vi-editor-copy-all-the-lines-to-clipboard

You should yank the text to the * or + registers:
gg"*yG
Explanation:
  • gg
    • gets the cursor to the first character of the file
  • "*y
    • Starts a yank command to the register * from the first line, until...
  • G
    • go the end of the file

[Shell] 利用 Shell Script 製作選單

如果想要用shellscript寫出程式執行選單可參考以下範例。 拿來寫一些每天常常會打的指令蠻方便的:D
#!/bin/bash
# Bash Menu Script Example

PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose choice 1"
            ;;
        "Option 2")
            echo "you chose choice 2"
            ;;
        "Option 3")
            echo "you chose choice 3"
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done

其他你感興趣的文章

Related Posts with Thumbnails