gpt4 book ai didi

javascript - 添加超链接时如何保持图像缩放

转载 作者:太空宇宙 更新时间:2023-11-04 08:24:33 28 4
gpt4 key购买 nike

我想在图库中添加一个指向图像的超链接(以便打开图像的放大版本),同时保持缩略图的“缩放”效果。我试图向第一张图片添加超链接,但缩放不再运行。如果我的解释不是很好,我深表歉意,我是编码语言的新手!任何帮助都会很棒!

这是我获得图库代码的链接,如果它对任何人都有用的话! https://codepen.io/oknoblich/pen/ELfzd

< script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" > < /script> <
script type = "text/javascript" >


(function() {

var documentElem = $(document),
nav = $('nav'),
lastScrollTop = 0;

documentElem.on('scroll', function() {
var currentScrollTop = $(this).scrollTop();

//scroll down
if (currentScrollTop > lastScrollTop) nav.addClass('hidden');
//scroll up
else nav.removeClass('hidden');

lastScrollTop = currentScrollTop;
});
})();

<
/script>
<!-- End of Javascript for Navigation Menu -->
<style type="text/css">@import url('https://fonts.googleapis.com/css?family=Open+Sans:300');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

.gallery {
width: 640px;
margin: 0 auto;
padding: 5px;
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

.gallery>div {
position: relative;
float: left;
padding: 5px;
}

.gallery>div>img {
display: block;
width: 200px;
transition: .1s transform;
transform: translateZ(0);
/* hack */
}

.gallery>div:hover {
z-index: 1;
}

.gallery>div:hover>img {
transform: scale(1.1, 1.1);
transition: .3s transform;
}

.cf:before,
.cf:after {
display: table;
content: "";
line-height: 0;
}

.cf:after {
clear: both;
}

h1 {
margin: 40px 0;
font-size: 30px;
font-weight: 300;
text-align: center;
}

</style>
<body>
<!-- Start of Navigation Bar -->
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li id="current"><a href="gallery.html">Gallery</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
<!-- End of Navigation Bar -->
<br />
<br />

<h1> Gallery </h1>

<!-- Stat of Gallery -->
<div class="gallery cf">
<!-- This is the image I tried to link but when I ran the code the zoom was no longer maintained. -->
<div>
<a href="Images/Optimized/FullImage_1.jpg"><img src="Images/Optimized/Thumbnail_1.jpg" width="200" height="300" alt="" /></a>
</div>
<div>
<img src="Images/Optimized/Thumbnail_2.jpg" width="200" height="300" alt="" /> </div>
<div>
<img src="Images/Optimized/Thumbnail_3.jpg" width="200" height="300" alt="" /> </div>
<div>
<img src="Images/Optimized/Thumbnail_4.jpg" width="200" height="300" alt="" /> </div>
<div>
<img src="Images/Optimized/Thumbnail_5.jpg" width="200" height="300" alt="" /> </div>
<div>
<img src="Images/Optimized/Thumbnail_6.jpg" width="200" height="300" alt="" /> </div>
</div>

最佳答案

这里是代码,它肯定会工作并且会以大尺寸显示图像。

https://jsfiddle.net/fsfrkru0/

HTML 和 CSS

@import url('https://fonts.googleapis.com/css?family=Open+Sans:300');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font: 14px/1 'Open Sans', sans-serif;
color: #555;
background: #e5e5e5;
}

.gallery {
width: 640px;
margin: 0 auto;
padding: 5px;
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

.gallery>div>a {
position: relative;
float: left;
padding: 5px;
}

.gallery>div>a>img {
display: block;
width: 200px;
transition: .1s transform;
transform: translateZ(0);
/* hack */
}

.gallery>div:hover>a {
z-index: 1;
}

.gallery>div:hover>a>img {
transform: scale(1.7, 1.7);
transition: .3s transform;
}

.cf:before,
.cf:after {
display: table;
content: "";
line-height: 0;
}

.cf:after {
clear: both;
}

h1 {
margin: 40px 0;
font-size: 30px;
font-weight: 300;
text-align: center;
}
<h1>Simple CSS Image Gallery with Zoom</h1>

<div class="gallery cf">
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
<div>
<a href="http://abload.de/img/a6aawu.jpg" target="_blank"><img src="http://abload.de/img/a6aawu.jpg" styles="" /></a>
</div>
</div>

希望这对您有所帮助。

关于javascript - 添加超链接时如何保持图像缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45266661/

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