我正在使用Magnific。
$(document).ready(function() {
$('.image-viewer').magnificPopup({
type: 'ajax'
});
});这是html:
<a href="/site-media/{{ photo.image }}" class="image-viewer"><img class="fest-content-event-content-photo" width = "100%" src="/site-media/{{ photo.thumbnail2 }}" /></a>但是,它不工作,控制台显示错误:
Uncaught TypeError: Property '$' of object [object Object] is not a function (index):30
(anonymous function) (index):30
fire jquery.js:3048
self.fireWith jquery.js:3160
jQuery.extend.ready jquery.js:433
completed怎么啦?我没有两次加载jquery.js文件。
发布于 2014-01-17 15:20:46
首先,确保正确地包含了jQuery库:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>其次,也许jQuery与其他库之间存在冲突,您可以尝试使用:
jQuery(document).ready(function ($) {
$('.image-viewer').magnificPopup({
type: 'ajax'
});
});发布于 2014-01-17 15:11:20
听起来你们之间有冲突..尝试在document.ready函数中添加$
$(document).ready(function($) {
$('.image-viewer').magnificPopup({
type: 'ajax'
});
});或者将$替换为jQuery this
jQuery(document).ready(function(){
jQuery('.image-viewer').magnificPopup({
type: 'ajax'
});
}发布于 2021-05-15 16:29:34
确保在要执行的代码之前放入JQuery和Magnific链接。
如下所示:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="jquery.magnific-popup.min.js"></script>
<script>
$(document).ready(function () {
$('#some-btn').magnificPopup({
items: [
{
src: './9414795.jpg'
}
],
gallery: {
enabled: true
},
type: 'image'
});
});
</script>https://stackoverflow.com/questions/21179828
复制相似问题