読者です 読者をやめる 読者になる 読者になる

ウェブ学のすすめ

Study of Web Design & Programing

jQuery tools scrollableとlightBoxの連携

jQuery tools scrollableとlightBoxがなかなか同時に動作しませんでしたが試行錯誤の上やっと動いてくれました。

プレビュー

↓拡大表示にすると見やすいです(右上のボタンが拡大表示)。

スマートフォンの方はこちらからプレビューできます。
scrollableとlightBox

コード

HTML
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>scrollableとlightBox</title>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery.tools.min.js"></script>
<script src="js/jquery.lightbox-0.5.min.js"></script>
<link rel="stylesheet" href="css/standalone.css">
<link rel="stylesheet" href="css/scrollable-horizontal.css">
<link rel="stylesheet" href="css/scrollable-buttons.css">
<link rel="stylesheet" href="css/jquery.lightbox-0.5.css">
<script>
    $(function() {
        $('#gallery a').lightBox();
    });
    
    $(function() {
     	$('.scrollable').scrollable();
     });
</script>
</head>
<body>
<div style="margin:0 auto; width: 634px; height:120px;">
<!-- "previous page" action -->
<a class="prev browse left"></a>
 
<!-- root element for scrollable -->
<div class="scrollable" id="scrollable">
 
  <!-- root element for the items -->
  <div class="items">
 
    <!-- 1-5 -->
    <div id="gallery">
      <a href="http://farm1.staticflickr.com/143/321464099_a7cfcb95cf.jpg" title="1"><img src="http://farm1.static.flickr.com/143/321464099_a7cfcb95cf_t.jpg"></a>
      <a href="http://farm1.staticflickr.com/153/399232237_6928a527c1.jpg" title="2"><img src="http://farm4.static.flickr.com/3089/2796719087_c3ee89a730_t.jpg"></a>
      <a href="http://farm4.staticflickr.com/3624/3323893148_8318838fbd.jpg" title="3"><img src="http://farm1.static.flickr.com/79/244441862_08ec9b6b49_t.jpg"></a>
      <a href="http://farm1.staticflickr.com/28/66523124_b468cf4978.jpg" title="4"><img src="http://farm1.static.flickr.com/28/66523124_b468cf4978_t.jpg"></a>
    </div>
 
    <!-- 5-10 -->
    <div id="gallery">
      <a href="http://farm4.staticflickr.com/3651/3445879840_7ca4b491e9.jpg" title="5"><img src="http://farm1.static.flickr.com/163/399223609_db47d35b7c_t.jpg"></a>
      <a href="http://farm1.staticflickr.com/135/321464104_c010dbf34c.jpg" title="6"><img src="http://farm1.static.flickr.com/135/321464104_c010dbf34c_t.jpg"></a>
      <a href="http://farm4.staticflickr.com/3023/3323897466_e61624f6de.jpg" title="7"><img src="http://farm1.static.flickr.com/40/117346184_9760f3aabc_t.jpg"></a>
      <a href="http://farm1.staticflickr.com/153/399232237_6928a527c1.jpg" title="8"><img src="http://farm1.static.flickr.com/153/399232237_6928a527c1_t.jpg"></a>
    </div>
 
    <!-- 10-15 -->
    <div id="gallery">
      <a href="http://farm4.staticflickr.com/3629/3323896446_3b87a8bf75.jpg" title="9"><img src="http://farm4.static.flickr.com/3629/3323896446_3b87a8bf75_t.jpg"></a>
      <a href="http://farm4.staticflickr.com/3023/3323897466_e61624f6de.jpg" title="10"><img src="http://farm4.static.flickr.com/3023/3323897466_e61624f6de_t.jpg"></a>
      <a href="http://farm4.staticflickr.com/3650/3323058611_d35c894fab.jpg" title="11"><img src="http://farm4.static.flickr.com/3650/3323058611_d35c894fab_t.jpg"></a>
      <a href="http://farm4.staticflickr.com/3635/3323893254_3183671257.jpg" title="12"><img src="http://farm4.static.flickr.com/3635/3323893254_3183671257_t.jpg"></a>
    </div>
 
  </div>
 
</div>
 
<!-- "next page" action -->
<a class="next browse right"></a>
</div>
</body>
</html>
CSS

<standalone.css

@charset "utf-8";

body {
    padding:50px 80px;
    font-family:"Lucida Grande","bitstream vera sans","trebuchet ms",sans-serif,verdana;
}

/* get rid of those system borders being generated for A tags */
a:active {
    outline:none;
}

:focus {
    -moz-outline-style:none;
}

<scrollable-horizontal.css

@charset "utf-8";
/*
  root element for the scrollable.
  when scrolling occurs this element stays still.
  */
.scrollable {

    /* required settings */
    position:relative;
    overflow:hidden;
    width: 550px;
    height:120px;

    /* custom decorations */
    border:1px solid #ccc;
    background:url(/media/img/gradient/h300.png) repeat-x;
}

/*
   root element for scrollable items. Must be absolutely positioned
   and it should have a extremely large width to accomodate scrollable
   items.  it's enough that you set the width and height for the root
   element and not for this element.
*/
.scrollable .items {
    /* this cannot be too large */
    width:20000em;
    position:absolute;
    clear:both;
}

.items div {
    float:left;
    width:680px;
}

/* single scrollable item */
.scrollable img {
    float:left;
    margin:20px 5px 20px 21px;
    background-color:#fff;
    padding:2px;
    border:1px solid #ccc;
    width:100px;
    height:75px;

    -moz-border-radius:4px;
    -webkit-border-radius:4px;
}

/* active item */
.scrollable .active {
    border:2px solid #000;
    position:relative;
    cursor:default;
}

<scrollable-buttons.css

@charset "utf-8";
/* this makes it possible to add next button beside scrollable */
.scrollable {
    float:left;
}

/* prev, next, prevPage and nextPage buttons */
a.browse {
    background:url(../images/hori_large.png) no-repeat;
    display:block;
    width:30px;
    height:30px;
    float:left;
    margin:40px 10px;
    cursor:pointer;
    font-size:1px;
}

/* right */
a.right { background-position: 0 -30px; clear:right; margin-right: 0px;}
a.right:hover { background-position:-30px -30px; }
a.right:active { background-position:-60px -30px; }


/* left */
a.left { margin-left: 0px; }
a.left:hover  { background-position:-30px 0; }
a.left:active { background-position:-60px 0; }

/* up and down */
a.up, a.down  {
    background:url(/media/img/scrollable/arrow/vert_large.png) no-repeat;
    float: none;
    margin: 10px 50px;
}

/* up */
a.up:hover { background-position:-30px 0; }
a.up:active { background-position:-60px 0; }

/* down */
a.down { background-position: 0 -30px; }
a.down:hover { background-position:-30px -30px; }
a.down:active { background-position:-60px -30px; }


/* disabled navigational button */
a.disabled {
    visibility:hidden !important;
}

jquery.lightbox-0.5.css

@charset "utf-8";
#jquery-overlay {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 90;
	width: 100%;
	height: 500px;
}
#jquery-lightbox {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	z-index: 100;
	text-align: center;
	line-height: 0;
}
#jquery-lightbox a img { border: none; }
#lightbox-container-image-box {
	position: relative;
	background-color: #fff;
	width: 250px;
	height: 250px;
	margin: 0 auto;
}
#lightbox-container-image { padding: 10px; }
#lightbox-loading {
	position: absolute;
	top: 40%;
	left: 0%;
	height: 25%;
	width: 100%;
	text-align: center;
	line-height: 0;
}
#lightbox-nav {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 100%;
	z-index: 10;
}
#lightbox-container-image-box > #lightbox-nav { left: 0; }
#lightbox-nav a { outline: none;}
#lightbox-nav-btnPrev, #lightbox-nav-btnNext {
	width: 49%;
	height: 100%;
	zoom: 1;
	display: block;
}
#lightbox-nav-btnPrev { 
	left: 0; 
	float: left;
}
#lightbox-nav-btnNext { 
	right: 0; 
	float: right;
}
#lightbox-container-image-data-box {
	font: 10px Verdana, Helvetica, sans-serif;
	background-color: #fff;
	margin: 0 auto;
	line-height: 1.4em;
	overflow: auto;
	width: 100%;
	padding: 0 10px 0;
}
#lightbox-container-image-data {
	padding: 0 10px; 
	color: #666; 
}
#lightbox-container-image-data #lightbox-image-details { 
	width: 70%; 
	float: left; 
	text-align: left; 
}	
#lightbox-image-details-caption { font-weight: bold; }
#lightbox-image-details-currentNumber {
	display: block; 
	clear: left; 
	padding-bottom: 1.0em;	
}			
#lightbox-secNav-btnClose {
	width: 66px; 
	float: right;
	padding-bottom: 0.7em;	
}

ポイント

lightboxjQuery lightBox pluginからダウンロードし、「jquery.lightbox-0.5.min.js」、「jquery.lightbox-0.5.css」と画像を使用

jQuery TOOLSからScrollable(3.8kb)のみダウンロード

↓フォルダー構成は以下のようにしました。

↓jsフォルダ

cssフォルダ

↓imagesフォルダ

JavascriptlightBox()を、HTMLにid="gallery"を追加

$(function() {
        $('#gallery a').lightBox();
    });
<div id="gallery">