简体   繁体   English

如何在 html/javascript 中组合 3 个图像

[英]How to combine 3 images in html/javascript

I have 3 <img> .我有 3 个<img>

<img id="img1" src="" alt="">
<img id="img2" src="" alt="">
<img id="img3" src="" alt="">

I want to show all 3 three of them simultaneously in one <div> but each image takes 1/3 of the <div> width (also the images should be cropped).我想在一个<div>同时显示所有三个三个,但每个图像占用<div>宽度的 1/3(图像也应该被裁剪)。 And whenever I hover a image the column should expand a little and reveal more of the image.每当我悬停image该列都应稍微展开并显示更多图像。

I thought of putting them together in a <canvas> and use WebGL but then I think I dont have the possibility to implement hover events.我想将它们放在<canvas>并使用 WebGL,但后来我认为我没有实现悬停事件的可能性。 Any Ideas?有任何想法吗?

You could use something like this if you wanted something in pure CSS.如果你想要纯 CSS 中的东西,你可以使用这样的东西。 It's a very rudimentary example but should get you started.这是一个非常基本的例子,但应该让你开始。 It uses CSS clip-path on the image elements and transition to modify the clipping on hover.它在图像元素和transition上使用 CSS clip-path来修改悬停时的剪辑。

 #img-wrap { width: 300px; height: 300px; position: relative; } #img-wrap img { clip-path: inset(0 66% 0 0); position: absolute; z-index: 0; transition: all .2s ease .2s; } #img-wrap img:nth-of-type(2) { left: 33%; } #img-wrap img:nth-of-type(3) { left: 66%; } #img-wrap img:hover { clip-path: inset(0 50% 0 0); z-index: 10; } #img-wrap img:nth-of-type(3):hover { left: 50%; }
 <div id="img-wrap"> <img src="http://placehold.it/300x300/39b54a/ffffff/"> <img src="http://placehold.it/300x300/f78200/ffffff/"> <img src="http://placehold.it/300x300/e6001f/ffffff/"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM