gpt4 book ai didi

html - 灯箱 2 不工作?

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:40 25 4
gpt4 key购买 nike

我使用的是最新的 lightbox 2 发行版。由于某种原因无法让它工作,当我点击图像时,它直接进入 href 而不是像它应该的那样出现。无论我是否使用 CDN 或 jquery-plus-lightbox 插件,javascript 都可以工作.. 这是我的代码:

<!DOCTYPE html>
<html>
<head>
<title>pGallery | View Portfolio</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/lightbox.min.css">


<script src="js/lightbox-plus-jquery.min.js"></script>
<script src="js/script.js"></script>
</head>
<body>
<section>
<div class="container">
<h1 id="heading">All Projects</h1>
<ul id="gallery">
<li class="design"><a href="images/web1.jpg" data-lightbox="projects" data-title="Project 1" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web1.jpg" /></a></li>
<li class="design programming"><a href="images/web2.jpg" data-lightbox="projects" data-title="Project 2" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web2.jpg" /></a></li>
<li class="design programming"><a href="images/web3.jpg" data-lightbox="projects" data-title="Project 3" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web3.jpg" /></a></li>
<li class="design programming cms"><a href="images/web4.jpg" data-lightbox="projects" data-title="Project 4" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web4.jpg" /></a></li>
<li class="programming"><a href="images/web5.jpg" data-lightbox="projects" data-title="Project 5" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web5.jpg" /></a></li>
<li class="design cms"><a href="images/web6.jpg" data-lightbox="projects" data-title="Project 6" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web6.jpg" /></a></li>
<li class="design cms"><a href="images/web7.jpg" data-lightbox="projects" data-title="Project 7" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web7.jpg" /></a></li>
<li class="design cms"><a href="images/web8.jpg" data-lightbox="projects" data-title="Project 8" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web8.jpg" /></a></li>
<li class="design programming cms"><a href="images/web9.jpg" data-lightbox="projects" data-title="Project 9" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web9.jpg" /></a></li>
<li class="cms"><a href="images/web10.jpg" data-lightbox="projects" data-title="Project 10" data-desc="Lorem ipsum dolor sit amet, consectetur adipiscing elituctor vitae velit mollis"><img src="images/web10.jpg" /></a></li>
</ul>
</div>
</section>
</body>

script.js 中的 JavaScript 代码:

$(document).ready(function() {

$('nav li').first().addClass('current');

$('nav a').on('click', function() {
$('nav li').removeClass('current');
$(this).parent().addClass('current');

$('h1#heading').text($(this).text());

var category = $(this).text().toLowerCase().replace(' ', '-');

if(category == 'all-projects') {
$('ul#gallery li:hidden').fadeIn('slow').removeClass('hidden');
} else {
$('ul#gallery li').each(function() {
if(!$(this).hasClass(category)) {
$(this).hide().addClass('hidden');
} else {
$(this).fadeIn('slow').removeClass('hidden');
}
});
}
return false;
});


$('ul#gallery li').on('mouseenter', function() {
var title = $(this).children().data('title');
var desc = $(this).children().data('desc');

if(desc == null) {
desc = 'Click to Enlarge';
}
if(title == null) {
title = '';
}

$(this).append('<div class="overlay"></div>');
var overlay = $(this).children('.overlay');
overlay.html('<h3>'+title+'</h3><p>'+desc+'</p>');
overlay.fadeIn(800);
});

$('ul#gallery li').on('mouseleave', function() {
$(this).append('<div class="overlay"></div>');
var overlay = $(this).children('.overlay');
overlay.fadeOut(500);
});


});

最佳答案

我认为问题在于您在 head 部分加载 Lightbox.js - 它本身不处理等待文档准备就绪,因此它会在加载任何页面内容之前检查页面上的灯箱。

快速修复 - 在关闭前加载 lightbox.js <body>标记而不是在 <head> 内.

或者,编辑 js 文件以包含准备好的文档。从 Lightbox v2.8.2 开始,您需要执行以下操作:

// line 27 (near top of file)
}(this, function ($) {
$(document).ready( function(){ // Add this line

// line 453 (near end of file)
return new Lightbox();
}); // Add this line
}));

关于html - 灯箱 2 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34440731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com