我有一些图片的链接,其中包括缩略图的链接http://example.com/img1_thumb.jpg
和原始大小的链接(任意比例)http://example.com/img1.jpg
。我在网格中展示缩略图,并希望当用户将鼠标悬停在网格中的图像上时显示原始大小的图像。也许可以使用浮动元素,目标是让用户能够更详细地查看图像并查看缩略图中裁剪的部分。
我该怎么做呢?我是HTML / CSS / Javascript的初学者。
我有一些图片的链接,其中包括缩略图的链接http://example.com/img1_thumb.jpg
和原始大小的链接(任意比例)http://example.com/img1.jpg
。我在网格中展示缩略图,并希望当用户将鼠标悬停在网格中的图像上时显示原始大小的图像。也许可以使用浮动元素,目标是让用户能够更详细地查看图像并查看缩略图中裁剪的部分。
我该怎么做呢?我是HTML / CSS / Javascript的初学者。
您可以在没有缩略图的情况下工作。
关于缩略图
<img src="http://example.com/img1.jpg" class="compress"/>
$(".compress").hover(function(){
$(".image").show();
});
完整图片
<img src="http://example.com/img1.jpg" class="image"/>
css
.compress{
width:20%;
/*aspect ratio will be maintained*/
}
.image{
display:none;
position:absolute;
}
虽然不完整,但我认为它可能会有所帮助。
$(function() {
$('#thumbnails img').click(function() {
$('#thumbnails').hide();
var src = $(this).attr('src').replace('.png', 'Large.png');
$('#largeImage').attr('src', src).show();
});
$('#largeImage').hide().click(function() {
$(this).hide();
$('#thumbnails').show();
});
});
<div id="thumbnails">
<img src="thumbnail1.png">...
</div>
<img id="largeImage" src="">
<div class="some_class"><img src="http://example.com/img1.jpg"></div>
,将其设置为display:none
,然后像这样为 thumb div
绑定事件:$(".thumb_class").hover(function(){
$(".some_class").show()
},
function(){
$(".some_class").hide()
}
div
。第二个 function
允许您在鼠标移出缩略图时隐藏
该 div。希望我表述得尽可能清楚。