我花了很多时间试图让这个Magnific Popup的东西在我的网站上本地工作,并且它一直将我链接到一个单独的图像页面,而不是获得我想要的弹出式查看器。
有谁知道我的错误在哪里以及如何让它发挥作用?
我是jQuery的新手,所以我对于为什么这段代码不能正常工作一无所知。
编辑:我需要下载哪些内容才能让它发挥作用吗?
所有三个源代码都在我的文件夹中,我确实检查了它们是否在正确的链接中,而且我还没有收到任何Magnific弹出窗口。
这就是我在文档中的内容:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="website.css" rel="stylesheet" type="text/css">
<script src="my_jquery.js"></script>
<title> Name </title>
<link href="magnific-popup.css" rel="stylesheet" type="text/css">
<link href="singleimage.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="navigation">
<div id="header_left"><span id="header_text1">Name</span> </div>
<div id="header_right"> <span id="header_text2">
<a href="#home">Link</a>
<a href="#name">Link</a>
<a href="#name">Link</a>
<a href="#name">Link</a>
<a href="#name">Link</a>
</span> </div>
</div>
<a name="graphicdesign">
<div class="bg-image2">
<div class="test1">
<div class="test2"> <h1>Page Title</h1>
<a class="image-popup-vertical-fit" href="cat_b.jpg" title="Caption. Can be aligned it to any side and contain any HTML.">
<img src="cat_s.jpg " width="75" height="75">
</a>
<a class="image-popup-fit-width" href="http://farm9.staticflickr.com/8379/8588290361_ecf8c27021_b.jpg" title="This image fits only horizontally.">
<img src="http://farm9.staticflickr.com/8379/8588290361_ecf8c27021_s.jpg" width="75" height="75">
</a>
<a class="image-popup-no-margins" href="http://farm4.staticflickr.com/3721/9207329484_ba28755ec4_o.jpg">
<img src="http://farm4.staticflickr.com/3721/9207329484_ba28755ec4_o.jpg" width="107" height="75">
</a>
<script>
$(document).ready(function() {
$('.image-link').magnificPopup({type:'image'});
});
$(document).ready(function() {
$('.image-popup-vertical-fit').magnificPopup({
type: 'image',
closeOnContentClick: true,
mainClass: 'mfp-img-mobile',
image: {
verticalFit: true
}
});
$('.image-popup-fit-width').magnificPopup({
type: 'image',
closeOnContentClick: true,
image: {
verticalFit: false
}
});
$('.image-popup-no-margins').magnificPopup({
type: 'image',
closeOnContentClick: true,
closeBtnInside: false,
fixedContentPos: true,
mainClass: 'mfp-no-margins mfp-with-zoom', // class to remove default margin from left and right side
image: {
verticalFit: true
},
zoom: {
enabled: true,
duration: 300 // don't foget to change the duration also in CSS
} }); });
</script>
<script src="jquery.magnific-popup.min.js"></script>
<script src="jquery.magnific-popup.js"></script>
<!-- jQuery 1.7.2+ or Zepto.js 1.0+ -->
</div>
</div>
</div> </a>
我从Magnific Popup粘贴的代码中得到了三个错误。我没有以任何方式更改代码,但我仍然遇到了错误。我不确定我是否应该以某种方式改变它。我很困惑该怎么做。
未捕获的ReferenceError:$未定义index_01.html:73
以下是该页第75行的一些代码:
<script>
$(document).ready(function() {
$('.image-link').magnificPopup({type:'image'});
});
Uncaught TypeError:undefined不是函数jquery.magnific-popup.min.js:4
(function(e){var t,n,i,o,r,a,s,l="Close",c="BeforeClose",d="AfterClose",u="BeforeAppend",p=
未捕获的TypeError:undefined不是函数jquery.magnific-popup.js:38
_window = $(window),
答案 0 :(得分:2)
好吧,正如我在评论中指出的那样,你应该在jQuery之后添加到magnific-popup.js的链接,因为这是一个插件:
<script src="jquery.min.js"></script>
<script src="magnific-popup.js"></script>
我创建了这个jsfiddle,这是你想要的(看起来有点令人毛骨悚然)?我还将所有脚本组合在一个块中,如下所示:
$(document).ready(function () {
$('.image-popup-vertical-fit').magnificPopup({
type: 'image',
delegate: 'a',
closeOnContentClick: true,
mainClass: 'mfp-img-mobile',
image: {
verticalFit: true
}
});
$('.parent-container').magnificPopup({
delegate: 'a', // child items selector, by clicking on it popup will open
type: 'image'
// other options
});
$('.image-popup-vertical-fit').magnificPopup({
type: 'image',
closeOnContentClick: true,
mainClass: 'mfp-img-mobile',
image: {
verticalFit: true
}
});
$('.image-popup-fit-width').magnificPopup({
type: 'image',
closeOnContentClick: true,
image: {
verticalFit: false
}
});
$('.image-popup-no-margins').magnificPopup({
type: 'image',
closeOnContentClick: true,
closeBtnInside: false,
fixedContentPos: true,
mainClass: 'mfp-no-margins mfp-with-zoom', // class to remove default margin from left and right side
image: {
verticalFit: true
},
zoom: {
enabled: true,
duration: 300 // don't foget to change the duration also in CSS
}
});
});