![](/img/trans.png)
[英]using lightGallery and Jekyll: TypeError: $(...).lightGallery is not a function
[英]$ is not defined lightgallery
出於某種原因,我的燈廊無法正常工作。 我以與往常相同的方式添加它,並且所有 javascript 文件都包含在 Jquery 之后。
我在控制台中收到此消息:
Uncaught TypeError: $ is not a function
at product-1.html:433
(anonymous) @ product-1.html:433
其中指出:
<script type="text/javascript">
$(document).ready(function($) {
$("#lightgallery").lightGallery();
});
</script>
所有文件都已正確加載,我檢查了網絡選項卡。
可能是什么問題,我該如何解決? 也許某處有沖突? 我可以將它包裝在一個函數中以使其工作嗎?
我的js文件:
在頭上
<link href="https://cdn.rawgit.com/sachinchoolur/lightgallery.js/master/dist/css/lightgallery.css" rel="stylesheet">
你的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>
在主體中包含 jquery 之后的燈光畫廊 js 文件
<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>
這真的對我有用。
清除瀏覽器緩存有時可能會有所幫助。 或者通過從 jquery 開始一一加載來縮小您的問題。
這解決了這個問題:
<script>
lightGallery(document.getElementById('lightgallery'));
</script>
1. 檢查你的地圖 api js 鏈接,如https://developers.google.com/maps/api/js這是否正確 2. 同時按下 Ctrl + Shift + Del按鈕並清除緩存和 cookie
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.