用Bootstrap+CSS3+JavaScript生成一个显示图片的示例网站
时间: 2023-08-11 20:06:10 浏览: 108
好的,以下是一个用Bootstrap、CSS3和JavaScript生成的示例网站,用于显示图片:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Image Gallery Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<style>
.gallery {
display: flex;
flex-wrap: wrap;
}
.gallery-item {
flex: 1 1 200px;
margin: 10px;
overflow: hidden;
border-radius: 5px;
cursor: pointer;
}
.gallery-item img {
width: 100%;
height: 100%;
object-fit: cover;
transition: transform 0.3s ease;
}
.gallery-item:hover img {
transform: scale(1.1);
}
#modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 999;
}
#modal-content {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
#modal img {
max-width: 80%;
max-height: 80%;
object-fit: contain;
}
#modal-close {
position: absolute;
top: 10px;
right: 10px;
font-size: 24px;
color: white;
cursor: pointer;
z-index: 1000;
}
</style>
</head>
<body>
<div class="container">
<h1 class="text-center mt-5">Image Gallery Example</h1>
<div class="gallery mt-5">
<div class="gallery-item" data-image="https://picsum.photos/id/1000/400/300">
<img src="https://picsum.photos/id/1000/400/300" alt="Image 1">
</div>
<div class="gallery-item" data-image="https://picsum.photos/id/1001/400/300">
<img src="https://picsum.photos/id/1001/400/300" alt="Image 2">
</div>
<div class="gallery-item" data-image="https://picsum.photos/id/1002/400/300">
<img src="https://picsum.photos/id/1002/400/300" alt="Image 3">
</div>
<div class="gallery-item" data-image="https://picsum.photos/id/1003/400/300">
<img src="https://picsum.photos/id/1003/400/300" alt="Image 4">
</div>
<div class="gallery-item" data-image="https://picsum.photos/id/1004/400/300">
<img src="https://picsum.photos/id/1004/400/300" alt="Image 5">
</div>
<div class="gallery-item" data-image="https://picsum.photos/id/1005/400/300">
<img src="https://picsum.photos/id/1005/400/300" alt="Image 6">
</div>
</div>
</div>
<div id="modal">
<div id="modal-content">
<img id="modal-image" src="">
<span id="modal-close">×</span>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script>
$(function() {
$('.gallery-item').click(function() {
var image = $(this).data('image');
$('#modal-image').attr('src', image);
$('#modal').show();
});
$('#modal-close').click(function() {
$('#modal').hide();
});
});
</script>
</body>
</html>
```
这个网站包含一个图片展示区域和一个模态框。图片展示区域使用Bootstrap的Grid System来排列图片,并使用CSS3的flex布局来自适应不同的屏幕尺寸。当鼠标悬停在图片上时,图片会放大,这是使用CSS3的transform属性实现的。当图片被点击时,它会在模态框中打开。模态框使用JavaScript来实现,当图片被点击时,它将显示模态框,并在其中显示所选图片。
你可以将此示例保存为HTML文件并在浏览器中打开,以查看它的外观和功能。
阅读全文