简体   繁体   English

未捕获的TypeError:$(...)。lightGallery不是一个函数

[英]Uncaught TypeError: $(…).lightGallery is not a function

when I try to click the link it shows this in browser console: 当我尝试单击链接时,它会在浏览器控制台中显示:

Uncaught TypeError: $(...).lightGallery is not a    function(anonymous function) @ index.html:250dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3

and this is the code I used: 这是我使用的代码:

    $('#gallery').on('click', function() {
    $(this).lightGallery({
        dynamic: true,
        dynamicEl: [{
            "src": 'assets/images/gallery/1.jpg',
            'thumb': 'assets/images/gallery/thumbs/1.jpg',
            'subHtml': '<h4>Fading Light</h4><p>Classic view from Rigwood Jetty on Coniston Water an old archive shot similar to an old post but a little later on.</p>'
        }, {
            'src': 'assets/images/gallery/2.jpg',
            'thumb': 'assets/images/gallery/thumbs/2.jpg',
            'subHtml': "<h4>Bowness Bay</h4><p>A beautiful Sunrise this morning taken En-route to Keswick not one as planned but I'm extremely happy I was passing the right place at the right time....</p>"
        }, {
            'src': 'assets/images/gallery/3.jpg',
            'thumb': 'assets/images/gallery/thumbs/3.jpg',
            'subHtml': "<h4>Coniston Calmness</h4><p>Beautiful morning</p>"
        }]
    })
});

bear in mind I am using the Dynamic Mode in lightGallery. 请记住我在lightGallery中使用动态模式。

  1. I already included the lightGallery library before and the jQuery library before it. 我之前已经包含了lightGallery库和之前的jQuery库。
  2. I have tried to substitute the $ with jQuery. 我试图用jQuery替换$。
  3. I also tried the "semicolon solution" but with no luck. 我也试过“分号解决方案”,但没有运气。

this is the whole libraries i included: 这是我包括的整个图书馆:

    <script src="assets/web/assets/jquery/jquery.min.js"></script>
  <script src="assets/tether/tether.min.js"></script>
  <script src="assets/bootstrap/js/bootstrap.min.js"></script>
  <script src="assets/smooth-scroll/SmoothScroll.js"></script>
  <script src="assets/viewportChecker/jquery.viewportchecker.js"></script>
  <script src="assets/cookies-alert-plugin/cookies-alert-core.js"></script>
  <script src="assets/cookies-alert-plugin/cookies-alert-script.js"></script>
  <script src="assets/dropdown/js/script.min.js"></script>
  <script src="assets/touchSwipe/jquery.touchSwipe.min.js"></script>
  <script src="assets/jarallax/jarallax.js"></script>
  <script src="assets/bootstrap-carousel-swipe/bootstrap-carousel-swipe.js"></script>
  <script src="assets/jquery-mb-ytplayer/jquery.mb.YTPlayer.min.js"></script>
  <script src="assets/theme/js/script.js"></script>
  <script src="assets/mobirise-slider-video/script.js"></script>
  <script src="assets/formoid/formoid.min.js"></script>
  <!-- lightgallery -->
  <script src="assets/theme/js/lightgallery.min.js"></script>
  <script src="assets/theme/js/lg-thumbnail.min.js"></script>
  <script src="assets/theme/js/lg-fullscreen.min.js"></script>
  <script src="assets/theme/js/lg-share.min.js"></script>
  <script src="assets/theme/js/lg-zoom.min.js"></script>
  <script src="assets/theme/js/lg-autoplay.min.js"></script>

Wooooooooooo Haaaaaa I finally solved it, and the problem was maybe with local version I have!! Wooooooooooo Haaaaaa我终于解决了它,问题可能是我有本地版本!! When I switched to the cdnjs version it worked PERFECT!!! 当我切换到cdnjs版本时,它工作完美! a huge THANKS for all of you!! 非常感谢大家! all I did is replace the local ones with the cdn links 我所做的只是用cdn链接替换本地的

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.3.2/css/lightgallery.css" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.3.2/js/lightgallery.js"></script>

in the head 在头上

<link href="https://cdn.rawgit.com/sachinchoolur/lightgallery.js/master/dist/css/lightgallery.css" rel="stylesheet">

your html. 你的HTML。

<div id="lightgallery">
  <a href="img/img1.jpg">
      <img src="img/thumb1.jpg" />
  </a>
  <a href="img/img2.jpg">
      <img src="img/thumb2.jpg" />
  </a>
</div>

in the body. 在身体里。 at the end after jquery 在jquery之后的最后

<script src="https://cdn.rawgit.com/sachinchoolur/lightgallery.js/master/dist/js/lightgallery.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-pager.js/master/dist/lg-pager.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-autoplay.js/master/dist/lg-autoplay.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-fullscreen.js/master/dist/lg-fullscreen.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-zoom.js/master/dist/lg-zoom.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-hash.js/master/dist/lg-hash.js"></script>
<script src="https://cdn.rawgit.com/sachinchoolur/lg-share.js/master/dist/lg-share.js"></script>
<script>
   lightGallery(document.getElementById('lightgallery'));
</script>

I make sure, this plugin was the last script in been called. 我确定,这个插件是被调用的最后一个脚本。 I also wrapped the code inside the ready function. 我还将代码包装在ready函数中。

In addition, I show how to use a variant to select elements from the DOM. 另外,我展示了如何使用变量从DOM中选择元素。 I'm using jQuery and running all from my local server. 我正在使用jQuery并从我的本地服务器运行所有。 The sources of lightgallery are from 2018, downloaded from the repository, manually. lightgallery的来源是2018年,手动从存储库下载。

<script  type="text/javascript">
      $(document).ready(function() {
        $('.post img').wrap(function(){
          return "<div class='gallery' data-src='" + $( this ).attr("src") + "'></div>";
        });

        lightGallery(document.querySelector('.post'), {selector: ".gallery"});
      });
    </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM