WEBデザインの勉強

初心者が1からWEBデザインを勉強するブログ。

Colorbox コールバック関数 独自のクローズボタンを追加

デモ
http://efu.sakura.ne.jp/web/colorbox/index2.html

以前書いた記事
mmmmofu.hatenablog.com

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Colorbox</title>
  <link rel="stylesheet" href="css/colorbox.css">
  <link rel="stylesheet" href="css/style2.css">
  <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <script src="js/jquery.colorbox.js"></script>
  <script src="js/script2.js"></script>
</head>
<body>
  <p class="btn_mobie"><a href="https://www.youtube.com/embed/wJbFMMQQ3Z0?rel=0&amp;autoplay=1&amp;showinfo=0" class="modal">YouTube</a></p>
  <p class="btn_movie_close">CLOSE</p>
</body>
</html>
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
  display: block;
}
body {
  line-height: 1;
}

.btn_mobie {
  padding: 50px 0;
  text-align: center;
}

.btn_mobie a {
  color: #333;
  font-size: 20px;
}

.btn_mobie a:focus {
  outline: none;
}

.btn_movie_close {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10000;
  cursor: pointer;
}
$(function(){
  $(".btn_mobie a").colorbox({
    iframe:true,
    innerWidth:960,
    innerHeight:540,
    maxWidth:"100%",
    onOpen:function(){//colorboxを読み込む直前
      alert('onOpen');
    },
    onLoad: function(){//読み込む直前
      $('.btn_movie_close').fadeIn(400);
      alert('onLoad');
    },
    onComplete: function(){//読み込みが完了
      alert('onComplete');
    },
    onCleanup: function(){//閉じる直前
      $('.btn_movie_close').fadeOut(300);
      alert('onCleanup');
    },
    onClosed: function(){//閉じる
      alert('onClosed');
    }
  });

  $('.btn_movie_close').on('click', function(){
    parent.$.fn.colorbox.close();
    return false;
  });
});