简体   繁体   中英

$ is not defined lightgallery

For some reason my lightgallery is not working. I added it the same way I always do and all javascript files are included after Jquery.

I get this message in the console:

Uncaught TypeError: $ is not a function
    at product-1.html:433
(anonymous) @ product-1.html:433

Which points to:

<script type="text/javascript">
    $(document).ready(function($) {
        $("#lightgallery").lightGallery();
    });
</script>

All files are correctly loaded, I checked in the network tab.

What could be the problem and how can I fix it? Maybe there is a conflict somewhere? Can I wrap it in a function to make it work?

My js files:

在此处输入图片说明

in the head

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

your html content

<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 include light gallery js files after 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>

This really works for me.

Clearing browser cache may help sometimes. Or narrow down your problem by loading one by one starting with jquery.

This solves the problem :

<script>
   lightGallery(document.getElementById('lightgallery'));
</script>

1. 检查你的地图 api js 链接,如https://developers.google.com/maps/api/js这是否正确 2. 同时按下 Ctrl + Shift + Del按钮并清除缓存和 cookie

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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