Fluid Box jQuery插件无法正常工作

时间:2014-12-15 07:37:46

标签: javascript jquery html css lightbox

有人可以告诉我为什么我的流体盒不适用于我的照片。我已按照所有说明创建了流式传感器的代码,但我的照片并未显示在网页上。但是,当您点击它应该在网页上的位置时,它会将您带到另一个包含我照片的页面。这是我的代码:

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootswatch: Cosmo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="./bootstrap.css" media="screen">
<link rel="stylesheet" href="bootstrap-lightbox.css">
<link rel="stylesheet" href="portfoliostyle.css">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="../bower_components/html5shiv/dist/html5shiv.js"></script>
  <script src="../bower_components/respond/dest/respond.min.js"></script>
<![endif]-->
<script>

 var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-23019901-1']);
  _gaq.push(['_setDomainName', "bootswatch.com"]);
    _gaq.push(['_setAllowLinker', true]);
  _gaq.push(['_trackPageview']);

 (function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
 })();

</script>
<script src="jquery.js"></script>
<script src="imagelightbox.js"></script>
<script>
$( function()
{
    $( 'a' ).imageLightbox();
});
</script>

</head>
<body>
<ul class="navigation">
<li class="nav-item"><a href="#">Home</a></li>
<li class="nav-item"><a href="#">Portfolio</a></li>
<li class="nav-item"><a href="#">About</a></li>
<li class="nav-item"><a href="#">Blog</a></li>
<li class="nav-item"><a href="#">Contact</a></li>
</ul>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger"></label>

<div class="site-wrap">
<div class="gallery">
<a class="space" href="images/spacetime.jpg" title="A Space in Time" data-fluidbox>
  <img src="images/spacetime.jpg" />
 </a>
  <a href="images/spacetime.jpg" data-fluidbox>
  <div class="fluidbox-wrap">
     <img src="images/spacetime.jpg" />
     <div class="fluidbox-ghost"></div>
    </div>
 </a>
</div>

</div>
<script src="https://code.jquery.com/jquery.min.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
$(function () {
// Global variables
var $fb = $('a[data-fluidbox');
vpRatio; // To store viewport aspect ratio
// Add class to all Fluidboxes
$fb.addClass('fluidbox');
// Create fluidbox modal background
$('body').append('<div id="fluidbox-overlay"></div>'); 
// Functions:
// 1. to close any opened Fluidbox
// 2. to position Fluidbox dynamically
var closeFb = function (){
    $('a[data-fluidbox].fluidbox-opened').trigger('click');
},
positionFb = function ($activeFb){
    // Get elements
    var $img = $activeFb.find('img'),
        $ghost = $activeFb.find('.fluidbox-ghost');

    // Calculate offset and scale
    var offsetY = $(window).scrollTop()-$img.offset().top+0.5*($img.data('imgHeight')*($img.data('imgScale')-1))+0.5*($(window).height()-$img.data('imgHeight')*$img.data('imgScale')),
        offsetX = 0.5*($img.data('imgWidth')*($img.data('imgScale')-1))+0.5*($(window).width()-    $img.data('imgWidth')*$img.data('imgScale')) - $img.offset().left,
        scale = $img.data('imgScale');

    // Animate wrapped elements
    // Parse integers:
    // 1. Offsets can be integers
    // 2. Scale is rounded to nearest 2 decimal places     
    $ghost.css({ 'transform':    'translate('+parseInt(offsetX*10)/10+'px,'+parseInt(offsetY*10)/10+'px)         scale('+parseInt(scale*1000)/1000+')' });
}
// The following events will force FB to close
// ... when the opqaue overlay is clicked upon
$('#fluidbox-bg').click(closeFb);
  })();

$fb.imagesLoaded().done(function (){
$fb
.wrapInner('<div class="fluidbox-wrap" />')
.find('img')
.css({ opacity: 1 })
.after('<div class="fluidbox-ghost" />');
// Listen to resize event for calculations
$(window).resize(function (){

// Get viewport aspect ratio (#1)
vpRatio = $(window).width() / $(window).height();

// Get dimensions and aspect ratios
$fb.each(function (){
    var $img = $(this).find('img'),
        $ghost = $(this).find('.fluidbox-ghost'),
        $wrap = $(this).find('.fluidbox-wrap'),
        data = $img.data();

    // Save image dimensions as jQuery object (#2)
    data.imgWidth = $img.width();
    data.imgHeight = $img.height();
    data.imgRatio = $img.width() / $img.height();

    // Resize ghost element (#3)
    $ghost.css({
        width: $img.width(),
        height: $img.height(),
        top: $img.offset().top - $wrap.offset().top,
        left: $img.offset().left - $wrap.offset().left
    });

    // Calculate scale based on orientation (#4)
    if(vpRatio > data.imgRatio) {
        data.imgScale = $(window).height()*.95 / $img.height();
    } else {
        data.imgScale = $(window).width()*.95 / $img.width();
    }
});
}).resize();
// Bind click event
$fb.click(function (e){

// Variables
var $img   = $(this).find('img'),
    $ghost = $(this).find('.fluidbox-ghost'),
    $wrap  = $(this).find('.fluidbox-wrap');

if($(this).data('fluidbox-state') == 0 || !$(this).data('fluidbox-state')) {
    // State: Closed
    // Action: Open Fluidbox
    $(this)
.data('fluidbox-state', 1)
.removeClass('fluidbox-closed')
.addClass('fluidbox-opened');
// Show overlay
$('#fluidbox-overlay').fadeIn();
// Set thumbnail image source as background image first.
// We also show the ghost element
$ghost.css({
'background-image': 'url('+$img.attr('src')+')',
opacity: 1
});
// Hide original image
$img.css({ opacity: 0 });

// Preload ghost image
var ghostImg = new Image();
ghostImg.onload = function (){ $ghost.css({ 'background-image': 'url('+$activeFb.attr('href')+')'    }   ); };
ghostImg.src = $(this).attr('href');

// Position Fluidbox
positionFb($(this));

} else {
    // State: Opened
    // Action: Close Fluidbox
    /// Switch state
$(this)
.data('fluidbox-state', 0)
.removeClass('fluidbox-opened')
.addClass('fluidbox-closed');

// Hide overlay
$('#fluidbox-overlay').fadeOut();

// Show original image
$img.css({ opacity: 1 });

// Hide ghost image
$ghost.css({ opacity: 0 });

// Reverse animation on wrapped elements
$ghost
.css({ 'transform': 'translate(0,0) scale(1)' })
.one('webkitTransitionEnd MSTransitionEnd oTransitionEnd transitionend', function (){
// Wait for transntion to run its course first
$ghost.css({ opacity: 0 });
});
    }
});


</script>

CSS:

/* Navigation Menu - Background */
.navigation {
/* critical sizing and position styles */
width: 100%;
height: 100%;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 0;

/* non-critical appearance styles */
list-style: none;
background: #111;
}

/* Navigation Menu - List items */
.nav-item {
/* non-critical appearance styles */
width: 200px;
border-top: 1px solid #111;
border-bottom: 1px solid #000;
}

.nav-item a {
/* non-critical appearance styles */
display: block;
padding: 1em;
background: linear-gradient(135deg, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
color: white;
font-size: 1.2em;
text-decoration: none;
transition: color 0.2s, background 0.5s;
}

.nav-item a:hover {
color: #c74438;
background: linear-gradient(135deg, rgba(0,0,0,0) 0%,rgba(75,20,20,0.65) 100%);
}

.site-wrap {
min-width: 100%;
min-height: 100%;
background-color: #fff;
position: absolute;
top: 0;
bottom: 100%;
left: 0;
z-index: 1;
 padding: 4em;
background-image: linear-gradient(135deg, 
                  rgb(254,255,255) 0%,
                  rgb(221,241,249) 35%,
                  rgb(160,216,239) 100%);
background-size: 200%;
}

.name {
position: absolute;
top: 60%;
right:40%;
}

h3{
text-align: center;
top: 65%;
}

/* Nav Trigger */
.nav-trigger {
/* critical styles - hide the checkbox input */
position: absolute;
clip: rect(0, 0, 0, 0);
}

label[for="nav-trigger"] {
/* critical positioning styles */
position: fixed;
left: 15px; top: 15px;
z-index: 2;

/* non-critical apperance styles */
height: 30px;
width: 30px;
cursor: pointer;
background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'    xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' x='0px' y='0px' width='30px' height='30px'   viewBox='0 0 30 30' enable-background='new 0 0 30 30' xml:space='preserve'><rect width='30' height='6'/>    <rect y='24' width='30' height='6'/><rect y='12' width='30' height='6'/></svg>");
background-size: contain;
}

/* Make the Magic Happen */
.nav-trigger + label, .site-wrap {
transition: left 0.2s;
}

.nav-trigger:checked + label {
left: 215px;
}

.nav-trigger:checked ~ .site-wrap {
left: 200px;
box-shadow: 0 0 5px 5px rgba(0,0,0,0.5);
}

 body {
/* Without this, the body has excess horizontal scroll when the menu is open */
overflow-x: hidden;
}

/* Additional non-critical styles */

h1, h3, p {
max-width: 600px;
margin: 0 auto 1em;
}

code {
padding: 2px;
background: #ddd;
}

/* Micro reset */
*,*:before,*:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-       box;margin:0;padding:0;}
html, body { height: 100%; width: 100%; font-family: Helvetica, Arial, sans-serif; }

/* Image Lightbox Galley */

a[data-fluidbox] {
background-color: #eee;
border: none;
cursor: -webkit-zoom-in;
cursor: -moz-zoom-in;
margin-bottom: 1.5rem;
}

a[data-fluidbox].fluidbox-opened {
cursor: -webkit-zoom-out;
cursor: -moz-zoom-out;
}

a[class^='float'] {
margin: 1rem;
margin-top: 0;
width: 33.33333%;
}

a.float-left {
float: left;
margin-left: 0;
}

a.float-right {
float: right;
margin-right: 0;
}

a[data-fluidbox] img {
display: block;
margin: 0 auto;
opacity: 0;
max-width: 100%;
transition: all .25s ease-in-out;
}

#fluidbox-overlay {
background-color: rgba(255,255,255,.85);
cursor: pointer;
cursor: -webkit-zoom-out;
cursor: -moz-zoom-out;
display: none;
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 500;
}
.fluidbox-wrap {
background-position: center center;
background-size: cover;
margin: 0 auto;
position: relative;
z-index: 400;
transition: all .25s ease-in-out;
}
.fluidbox-opened .fluidbox-wrap {
    z-index: 600;
}
.fluidbox-ghost {
     background-size: cover;
     background-position: center center;
     position: absolute;
     transition: all .25s ease-in-out;
}

.space img{
height: 25%;
width: 50%
}

0 个答案:

没有答案