TypeError:$(...)。magnificPopup不是函数

问题描述 投票:1回答:2

我是Chrome开发者版。该库未加载,我无法弄清楚原因。 Chrome控制台中报告错误。这是我的代码:

<ul><li><a class="mediaimage-link" href="~/img/HP/mediakit/The-CorPath-Vascular-Robotic-System_HR.jpg"><img src="~/img/HP/The-CorPath-Vascular Robotic-System-187.jpg" alt="">
</a></li>
<li><a href="https://www.youtube.com/watch?v=TnQsToiKKgw?rel=0&amp;showinfo=0" class="popup-youtube"> <img src="~/img/HP/Iyer-Video-187.jpg" alt=""></a>
         </li>
</ul>

$(document).ready(function() {
  //Media Image Popup
  $('.mediaimage-link').magnificPopup({type:'image'});
  //Video Iframe Popup
    $('.popup-youtube').magnificPopup({
          disableOn: 700,
          type: 'iframe',
          mainClass: 'mfp-fade',
          removalDelay: 160,
          preloader: false,
          fixedContentPos: false
        });
});`
javascript html magnific-popup
2个回答
2
投票

您可能没有在代码中包含JQuery库。请记住,JQuery文件必须放在所有其他Javascript代码之上。


1
投票
$(document).ready(function ($) {
    $('.test-popup-link').magnificPopup({
    type: 'image',
    gallery: {
            enabled: true,
            navigateByImgClick: true,
            preload: [0,1] // Will preload 0 - before current, and 1 after the current image
          }
    // other options
  });
  });

只需通过$(document).ready(function ($) $,它就会开始工作

© www.soinside.com 2019 - 2024. All rights reserved.