[英]Responsive tiled overlay gallery
Not sure if this is the correct place to post but I was wondering if someone could point me in the right direction. 不知道这是张贴的正确地点,但我想知道是否有人可以指出我正确的方向。 I'm trying to create a gallery-esque type of thing but not sure what to search for.
我正在尝试创建类似画廊的类型的东西,但不确定要搜索什么。
What I am trying to achieve is to create something like the following: http://avawa.radiuzz.com/home/ 我试图实现的目标是创建如下所示的内容: http : //avawa.radiuzz.com/home/
I want to have a picture that when I hover over (on desktop) or click on (mobile), will pop up an overlay where I can place a title and then a couple links underneath it. 我想要一张图片,当我将鼠标悬停在(在桌面上)或单击(在移动设备上)时,将弹出一个叠加层,我可以在其中放置标题,然后在其下方放置几个链接。
I've managed to somewhat create something but I can't get it to be responsive and when viewed on mobile, the hover option doesn't work so the overlay won't pop up. 我设法创建了一些东西,但是我无法使其具有响应性,并且在移动设备上查看时,悬停选项不起作用,因此不会弹出叠加层。
<div class="media">
<img class="media__image" src="_img/animation.jpg" alt="Animation Image">
<div class="media__body">
<h2>Animation</h2>
<div class="program-info">
<p><a href="#"><i class="fa fa-film fa-fw fa-lg"></i> Program Page</a></p>
<p><a href="#"><i class="fa fa-file-o fa-fw fa-lg"></i> Student Reel</a></p>
</div>
</div>
</div>
Here's the CSS: 这是CSS:
.media{display:inline-block;position:relative;vertical-align:top;margin:0 5px}
.media:first-child{margin-left:0}
.media:last-child{margin-right:0}
.media__image{display:block}
.media__body{background:rgba(255,255,255,.83);color:#000;font-size:2.4rem;left:10px;opacity:0;overflow:hidden;padding:7rem 3rem;position:absolute;top:10px;right:10px;bottom:10px;-webkit-transition:.6s;transition:.6s}
.media__body:hover{opacity:1}
.media__body h2{margin-top:0;font-size:4.8rem}
.media__body .program-info{margin-left:10rem}
.media__body p{margin-bottom:1rem}
If someone could help me out in trying to create something a little better like the supplied link or at least point me to what/where I should be looking to learn how to do this, that would be great. 如果有人可以帮助我尝试创建一些更好的东西(如提供的链接),或者至少将我指向我应该寻找的方法/位置,以学习如何做,那将很棒。
It looks like you have the normal, larger size with hover state figured out pretty well so my answer will really just target the small screen/ mobile version. 看来您具有正常的较大尺寸,并且具有很好的悬浮状态,所以我的回答实际上只会针对小屏幕/移动版本。
First, you're going to need javascript(jQuery in this instance) to detect the screen width on load. 首先,您将需要javascript(在本例中为jQuery)来检测加载时的屏幕宽度。 I detected for width less than 1024 and height less than 768, but you could easily adjust those in the code.
我检测到宽度小于1024,高度小于768,但是您可以轻松地在代码中进行调整。
In the HTML, I added a second class, .hover__box, to your .media__body div in order to have a selector to target while removing .media__body, which controls the hover, based on the screen size. 在HTML中,我向您的.media__body div中添加了第二个类.hover__box,以便在删除.media__body时有一个选择器作为目标,该控件根据屏幕大小来控制悬浮。 The short of it is that I remove .media_body and add .mobile__body, then added some jQuery to control clicking.
简短的是,我删除了.media_body并添加了.mobile__body,然后添加了一些jQuery来控制点击。
Here's the new HTML (with a placeholder image added): 这是新的HTML(添加了占位符图像):
<div class="media">
<img class="media__image" src="http://loremflickr.com/320/240/dog" alt="Animation Image">
<div class="media__body hover__box">
<h2>Animation</h2>
<div class="program-info">
<p><a href="#"><i class="fa fa-film fa-fw fa-lg"></i> Program Page</a></p>
<p><a href="#"><i class="fa fa-file-o fa-fw fa-lg"></i> Student Reel</a></p>
</div>
</div>
</div>
Here's what I added to the CSS: 这是我添加到CSS的内容:
.hover__box{background:rgba(255,255,255,.83);color:#000;font-size:2.4rem;left:10px;overflow:hidden;padding:7rem 3rem;position:absolute;top:10px;right:10px;bottom:10px;}
Here's the JS: 这是JS:
$( document ).ready(function() { // on DOM ready
var width = $(window).width(), height = $(window).height(); //setting width and height variables
if ((width <= 1023) && (height <= 767)) { //checks to see if the width is mobile sizes or not
$(".hover__box").removeClass("media__body"); // removes hover class
$(".hover__box").addClass("mobile__body"); // add mobile jQuery target class
$(".hover__box").hide(); // hide the hover box
$(".media__image").addClass("mobile__ready"); // add class to image so that it can be clicked specific to mobile
}
// show hover box when image is clicked on mobile
$(".media__image.mobile__ready").click(function() {
$(".hover__box").show();
});
// hide hover box when it is clicked on mobile
$(".hover__box.mobile__body").click(function() {
$(".hover__box").hide();
});
});
Here's a JSFiddle that works but you'll need to resize the box where the preview is in order to see the larger size: http://jsfiddle.net/overwine/v97m2c8n/3/ 这是一个可以使用的JSFiddle,但您需要调整预览所在的框的大小才能看到更大的尺寸: http : //jsfiddle.net/overwine/v97m2c8n/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.