[英]How to set close button X to Bootstrap gallery lightbox?
I have a bootstrap image gallery with lightbox and I'd like to show the close button X on the modal lightbox. 我有一个带有灯箱的自举图片库,我想在模式灯箱上显示关闭按钮X。 This is my HTML:
这是我的HTML:
<div class="col-lg-4 col-sm-6 col-xs-12">
<div class="thumbnail">
<a href="https://farm1.staticflickr.com/665/23578574946_b6f90e1ca8_k.jpg" data-toggle="lightbox">
<img src="https://farm1.staticflickr.com/665/23578574946_b6f90e1ca8_k.jpg" class="img-fluid">
</a>
</div>
</div>
And this is my JS: 这是我的JS:
$(document).on('click', '[data-toggle="lightbox"]', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
})
I know, I should set 'alwaysShowClose' to 'true' but I don't understand where. 我知道,我应该将“ alwaysShowClose”设置为“ true”,但我不知道在哪里。
You pass the paramenter on the function call 您在函数调用中传递参数
$(document).on('click', '[data-toggle="lightbox"]', function(event) {
event.preventDefault();
$(this).ekkoLightbox({
alwaysShowClose: true
});
})
The close button for a modal in Bootstrap 4 is this: Bootstrap 4中模态的关闭按钮是这样的:
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
The ×
×
thingy is the X. 麻烦的是X。
But in order for that button to work, you must use proper modal components. 但是,为了使该按钮起作用,您必须使用适当的模式组件。
Here's a working example: 这是一个工作示例:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script> <!-- Button trigger modal --> <div class="container m-1"> <div class="row"> <div class="col-lg-4 col-sm-6"> <button type="button" class="btn" data-toggle="modal" data-target="#exampleModal"> <div class="thumbnail"> <img src="https://farm1.staticflickr.com/665/23578574946_b6f90e1ca8_k.jpg" class="img-fluid"> </div> </button> </div> </div> </div> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <img class="img-fluid" src="https://farm1.staticflickr.com/665/23578574946_b6f90e1ca8_k.jpg" alt=""> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
Reference: 参考:
https://getbootstrap.com/docs/4.0/components/modal/ https://getbootstrap.com/docs/4.0/components/modal/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.