jquery - Simplelightbox 不适用于 jQuery 3.4.1
问题描述
我在让 Simplelightbox 工作时遇到问题。我遵循了 Traversy 的教程,但似乎无法弄清楚我做错了什么。
在我的 index.html 里面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/simple-lightbox.min.css">
<title>Simplelightbox Test</title>
</head>
<body>
<div class="gallery">
<a href="https://i7.pngguru.com/preview/523/198/482/google-logo-google-search-google-play-google.jpg"><img src="https://i7.pngguru.com/preview/523/198/482/google-logo-google-search-google-play-google.jpg" alt="photo"></a>
<a href="https://chromeunboxed.com/wp-content/uploads/2016/10/GoogleAssistant-1200x550.png"><img src="https://chromeunboxed.com/wp-content/uploads/2016/10/GoogleAssistant-1200x550.png" alt="two"></a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="simple-lightbox.min.js"></script>
<script>
$(function() {
const $gallery = $('.gallery a').simpleLightbox();
});
</script>
</body>
</html>
解决方案
在 HTML 文件中包含脚本
<script src="https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/2.1.3/simple-lightbox.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/simplelightbox/2.1.3/simple-lightbox.jquery.min.js"></script>
<div class="gallery">
<a href="https://images.pexels.com/photos/850602/pexels-photo-850602.jpeg?cs=srgb&dl=photography-of-three-dogs-looking-up-850602.jpg&fm=jpg">
<img src="https://images.pexels.com/photos/850602/pexels-photo-850602.jpeg?cs=srgb&dl=photography-of-three-dogs-looking-up-850602.jpg&fm=jpg" width="250" />
</a>
<a href="https://images.pexels.com/photos/319975/pexels-photo-319975.jpeg?cs=srgb&dl=adorable-animal-blur-breed-319975.jpg&fm=jpg">
<img src="https://images.pexels.com/photos/319975/pexels-photo-319975.jpeg?cs=srgb&dl=adorable-animal-blur-breed-319975.jpg&fm=jpg" width="250" />
</a>
</div>
然后只需在您的 JS 文件中调用该函数
$('.gallery a').simpleLightbox();
推荐阅读
- python - Discord.py 循环数据到文本文件?
- r - R, 两边合闸
- javascript - 有没有办法让两个数字整除并打印更大的数字
- php - 如何将这些查询与另一个父表中的 where 子句组合成单个查询?
- c# - 即使我添加了测试单元,sonarqube 的覆盖率也始终为 0%
- unit-testing - 在 tests/test.rs 文件中无法识别 src/main.rs 中定义的类型
- javascript - 从递延函数 for() 计数
- svelte - 如何在 SvelteKit 中获取用户代理加载功能
- python - 包装马拉松
- angularjs - angularjs 绑定到模板中打印的 html 中的 $scope 值