Javascript 为什么不是';我的fancybox功能不工作吗?
如果这是显而易见的事情,请原谅我,但我无法让我的fancybox工作。我知道我的自定义javascript正在向预览图像添加适当的class&href属性,但由于某些原因,浏览器无法识别我的fancybox函数。当我用Chrome DevTool检查页面时,它给了我一个错误“Uncaught TypeError:undefined不是一个函数”,我认为这意味着解析器没有识别Javascript 为什么不是';我的fancybox功能不工作吗?,javascript,jquery,html,fancybox,Javascript,Jquery,Html,Fancybox,如果这是显而易见的事情,请原谅我,但我无法让我的fancybox工作。我知道我的自定义javascript正在向预览图像添加适当的class&href属性,但由于某些原因,浏览器无法识别我的fancybox函数。当我用Chrome DevTool检查页面时,它给了我一个错误“Uncaught TypeError:undefined不是一个函数”,我认为这意味着解析器没有识别.fancybox()函数。我的全尺寸图像可能太大了吗?我相信这是显而易见的,但如果有人能告诉我错误是什么,我将不胜感激 这
.fancybox()
函数。我的全尺寸图像可能太大了吗?我相信这是显而易见的,但如果有人能告诉我错误是什么,我将不胜感激
这是我的网站:
这是我的HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="" />
<meta name="author" content="Brewmaster" />
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<title>Ryan M Brewer</title>
<link rel="stylesheet" type="text/css" href="includes/jquery.fancybox- 1.3.4/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<link href='http://fonts.googleapis.com/css?family=Poller+One' rel='stylesheet' type='text/css'/>
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
<link rel="stylesheet" type="text/css" href="includes/gallery.css" />
<link rel="stylesheet" href="../css/main-styles.css" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>
<script type="text/javascript" src="includes/farinspace/jquery.imgpreload.min.js"></script>
<script type="text/javascript" src="includes/jquery.fancybox-1.3.4/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="images/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<!--[if lt IE 9]>
<script src="js/ieshim/dist/html5shiv.js"></script>
<![endif]-->
<script type="text/javascript" src="includes/gallery.js"></script>
</head>
<body onLoad="">
<div class="contain">
<header id="header">
<div id="topSpacer"></div>
<div id="topbar">
<div class="topnav-container">
<nav class="topnav-left">
<ul>
<li><a href="../index.html">HOME</a></li>
<li><a href="../index.html#about">ABOUT ME</a></li>
<li><a href="../index.html#contact">CONTACT ME</a></li>
</ul>
</nav>
<nav class="topnav-right">
<ul>
<li><a href="webdesign.html">WEB DESIGN</a></li>
<li><a href="#">PHOTOS</a></li>
<li><a href="graphics.html">GRAPHICS</a></li>
</ul>
</nav>
<nav id="mobile-menu-tablet">
<button id="menuButton">MENU</button>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT ME</a></li>
<li><a href="#">CONTACT ME</a></li>
<li><a href="#">WEB DESIGN</a></li>
<li><a href="#">PHOTOS</a></li>
<li><a href="#">VIDEOS</a></li>
</ul>
</nav>
<nav id="mobile-menu-phone">
<button id="mobileMenuButton">MENU</button>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">ABOUT ME</a></li>
<li><a href="#">CONTACT ME</a></li>
<li><a href="#">WEB DESIGN</a></li>
<li><a href="#">PHOTOS</a></li>
<li><a href="#">VIDEOS</a></li>
</ul>
</nav>
<div class="logo-container"><a href="#"></a></div>
</div> <!--Closes topnav-container-->
</div> <!--Closes topbar-->
</header>
<body>
<div class="gallery_container">
<div class="gallery_credit"><h1>My Photography</h1></div>
<div class="clear_both"></div>
<div class="gallery_content">
<div class="gallery_thumbnails">
<a href="images/gallery/fireboat_fullsize.jpg" title="'Fireboat', Collection: Architecture"><img src="images/gallery/fireboat_thumbnail.jpg"/></a>
<a href="images/gallery/windows_fullsize.jpg" title="'Windows', Collection: Architecture"><img src="images/gallery/windows_thumbnail.jpg"/></a>
<a href="images/gallery/capitolflower_fullsize.jpg" title="'Capitol Flower', Collection: Architecture"><img src="images/gallery/capitolflower_thumbnail.jpg"/></a>
<a href="images/gallery/caughtintheteeth_fullsize.jpg" title="'Caught In The Teeth', Collection: Nature"><img src="images/gallery/caughtintheteeth_thumbnail.jpg"/></a>
<a href="images/gallery/crimsonbloom_fullsize.jpg" title="'Crimson Bloom', Collection: Nature"><img src="images/gallery/crimsonbloom_thumbnail.jpg"/></a>
<a href="images/gallery/familyisbeautiful_fullsize.jpg" title="'Family Is Beautiful', Collection: People"><img src="images/gallery/familyisbeautiful_thumbnail.jpg"/></a>
<a href="images/gallery/fanme_fullsize.jpg" title="'Fan Me', Collection: People"><img src="images/gallery/fanme_thumbnail.jpg"/></a>
<a href="images/gallery/flutterby_fullsize.jpg" title="'Flutterby', Collection: Nature"><img src="images/gallery/flutterby_thumbnail.jpg"/></a>
<a href="images/gallery/lightlyd_fullsize.jpg" title="'Light Lyd', Collection: People"><img src="images/gallery/lightlyd_thumbnail.jpg"/></a>
<a href="images/gallery/nicedew_fullsize.jpg" title="'Nice Dew', Collection: Nature"><img src="images/gallery/nicedew_thumbnail.jpg"/></a>
<a href="images/gallery/orangedream_fullsize.jpg" title="'Orange Dream', Collection: Nature"><img src="images/gallery/orangedream_thumbnail.jpg"/></a>
<a href="images/gallery/papabuddha_fullsize.jpg" title="'Papa Buddha', Collection: People"><img src="images/gallery/papabuddha_thumbnail.jpg"/></a>
<a href="images/gallery/pinkflamingos_fullsize.jpg" title="'Pink Flamingos', Collection: People"><img src="images/gallery/pinkflamingos_thumbnail.jpg"/></a>
<a href="images/gallery/redleaf_fullsize.jpg" title="'Red Leaf', Collection: Nature"><img src="images/gallery/redleaf_thumbnail.jpg"/></a>
<a href="images/gallery/satchel_fullsize.jpg" title="'Satchel', Collection: People"><img src="images/gallery/satchel_thumbnail.jpg"/></a>
<a href="images/gallery/scenicview_fullsize.jpg" title="'Scenic View', Collection: Architecture"><img src="images/gallery/scenicview_thumbnail.jpg"/></a>
<a href="images/gallery/stemout_fullsize.jpg" title="'Stem Out', Collection: Nature"><img src="images/gallery/stemout_thumbnail.jpg"/></a>
<a href="images/gallery/theroadatnight_fullsize.jpg" title="'The Road At Night', Collection: Nature"><img src="images/gallery/theroadatnight_thumbnail.jpg"/></a>
<a href="images/gallery/willitsfog_fullsize.jpg" title="'Willits Fog', Collection: Nature"><img src="images/gallery/willitsfog_thumbnail.jpg"/></a>
<a href="images/gallery/lightways_fullsize.jpg" title="'Lightways', Collection: Architecture"><img src="images/gallery/lightways_thumbnail.jpg"/></a>
<div class="clear_both"></div>
</div>
<div class="gallery_preview">
<a href="images/gallery/acrobats_large.jpg"></a>
</div>
<div class="clear_both"></div>
<div class="gallery_contact"><p><a class="contactLink" href="mailto:info@lynda.com">Contact Me</a></p></div>
<div class="gallery_caption"></div>
<div class="clear_both"></div>
<div class="gallery_preload_area"></div>
</div>
</div>
<div class="spacer"></div>
</body>
<footer>
<p>© Copyright 2013 - Ryan Michael Brewer</p>
</footer>
</html>
瑞安·M·布鲁尔
菜单
菜单
我的摄影
&抄袭;版权所有2013-Ryan Michael Brewer
以下是我的自定义Javascript:
$(document).ready(function() {
// Set these DIVs to show for browsers suporting JavaScipt
$('.gallery_data').css('display','block');
$('.gallery_thumbnails').css('width','500px');
$('.gallery_preview').css('display','block');
$('.gallery_caption').css('display','block');
// Capture the thumbnail links
$('.gallery_thumbnails a').click(function(e){
// Disables standard link behavior
e.preventDefault();
// Sets up variables based on linked thumbnails
var photo_caption = $(this).attr('title');
var photo_fullsize = $(this).attr('href');
var photo_preview = photo_fullsize.replace("_fullsize", "_preview");
// Fade out preview, preload new image, fade preview back in
$('.gallery_caption').slideUp(500);
$('.gallery_preview').fadeOut(500, function(){
$('.gallery_preload_area').html('<img src="'+photo_preview+'" />');
$('.gallery_preload_area img').imgpreload(function(){
$('.gallery_preview').html('<a class="overlayLink" title="'+photo_caption+'" href="'+photo_fullsize+'" style="background-image:url('+photo_preview+');"></a>');
$('.gallery_preview').fadeIn(500);
$('.gallery_caption').html('<p><a class="overlayLink zoom" title="'+photo_caption+'" href="'+photo_fullsize+'">View larger</a></p><p>'+photo_caption+'</p>');
$('.gallery_caption').slideDown(500);
setFancyBoxLinks();
updateThumbnails();
});
});
});
// Set the first preview image
var first_photo_caption = $('.gallery_thumbnails a').first().attr('title');
var first_photo_fullsize = $('.gallery_thumbnails a').first().attr('href');
var first_photo_preview = first_photo_fullsize.replace("_fullsize", "_preview");
$('.gallery_preview').html('<a class="overlayLink" title="'+first_photo_caption+'" href="'+first_photo_fullsize+'" style="background-image:url('+first_photo_preview+');"></a>');
$('.gallery_caption').html('<p><a class="overlayLink zoom" title="'+first_photo_caption+'" href="'+first_photo_fullsize+'">View larger</a></p><p>'+first_photo_caption+'<a href="'+first_photo_fullsize+'" style="background-image:url('+first_photo_preview+');"></a></p>');
updateThumbnails();
setFancyBoxLinks();
});
function setFancyBoxLinks(){
// Links for Fancybox
$("a.overlayLink").fancybox({
'titlePosition' : 'over',
'overlayColor' : '#000',
'overlayOpacity' : 0.8,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'autoScale' : true
});
}
function updateThumbnails(){
$('.gallery_thumbnails a').each(function(index){
if ( $('.gallery_preview a').attr('href') == $(this).attr('href') ){
$(this).addClass('selected');
$(this).children().fadeTo(250, .4);
}else {
$(this).removeClass('selected');
$(this).children().css('opacity', '1');
}
});
}
$(文档).ready(函数(){
//设置这些div以显示支持JavaScipt的浏览器
$('.gallery_data').css('display','block');
$('gallery_缩略图').css('width','500px');
$('.gallery_preview').css('display','block');
$('.gallery_caption').css('display','block');
//捕获缩略图链接
$('.gallery_缩略图a')。单击(函数(e){
//禁用标准链接行为
e、 预防默认值();
//基于链接的缩略图设置变量
var photo_caption=$(this.attr('title');
var photo_fullsize=$(this.attr('href');
var photo_preview=photo_fullsize.replace(“_fullsize”,“_preview”);
//淡出预览、预加载新图像、淡入预览
元(图库标题).幻灯片(500);;
$('.gallery_preview')。淡出(500,函数(){
$('.gallery\u preload\u area').html('';
$('.gallery\u preload\u area img').imgpreload(函数(){
$('.gallery_preview').html('');
美元("画廊预览").法代因(500美元),;
$('.gallery_caption').html(''+photo_caption+'');
$('gallery_caption')。向下滑动(500);
setFancyBoxLinks();
updateThumbnails();
});
});
});
//设置第一个预览图像
var first_photo_caption=$('.gallery_缩略图a').first().attr('title');
var first_photo_fullsize=$('.gallery_缩略图a').first().attr('href');
var first_photo_preview=first_photo_fullsize.replace(“_fullsize”,“_preview”);
$('.gallery_preview').html('');
$('.gallery_caption').html(''+first_photo_caption+'');
updateThumbnails();
setFancyBoxLinks();
});
函数setFancyBoxLinks(){
//Fancybox的链接
$(“a.OverlyLink”).fancybox({
“标题位置”:“结束”,
“套色”:“000”,
“产能过剩”:0.8,
“transitionIn”:“弹性”,
“transitionOut”:“弹性”,
“自动缩放”:真
});
}
函数updatehumbnails(){
$('.gallery_缩略图a')。每个(函数(索引){
if($('.gallery_preview a').attr('href')==$(this.attr('href')){
$(this.addClass('selected');
$(this.children().fadeTo(250.4);
}否则{
$(this.removeClass('selected');
$(this.children().css('opacity','1');
}
});
}
问题在于fancybox插件。您可以选择:将jQuery降级为或。我知道我遗漏了一些明显的东西。万分感谢!没问题@Ryanbrewer许多人可能不想将fancybox从v1.3.4升级到v2.x,因为他们的许可证方案不同。许多人必须找到替代方案。