简体   繁体   English

打开时灯箱未对齐

[英]Lightbox not aligned when opened

I'm having this issue on the lightbox when it opens, it doesn't centralize as it "should".当它打开时,我在灯箱上遇到了这个问题,它没有像“应该”那样集中。 I played around with the positioning and widths/heights, but I'm still not there... Maybe one of you can help me out on this.我玩弄了定位和宽度/高度,但我仍然不在那里......也许你们中的一个可以帮助我解决这个问题。 I opened a codepen to help you see what I mean: https://codepen.io/cucurutcho/pen/dgwjbj我打开了一个codepen来帮助你理解我的意思: https ://codepen.io/cucurutcho/pen/dgwjbj

<main>
  <input id="tab1" type="radio" name="tabs" checked>

  <label for="tab1">Portfolio</label>

  <section id="content1">
    <div class="container">
      <img src="https://unsplash.it/700/600?image=634" />
      <img src="https://unsplash.it/700/300?image=455" />
      <img src="https://unsplash.it/1500/700?image=629" />
      <img src="https://unsplash.it/700?image=594" />
      <img src="https://unsplash.it/700/450?image=417" />
      <img src="https://unsplash.it/700/400?image=410" />
      <img src="https://unsplash.it/700/550?image=628" />
      <img src="https://unsplash.it/700/450?image=421" />
      <img src="https://unsplash.it/700/567?image=572" />
      <img src="https://unsplash.it/700/978?image=623" />
      <img src="https://unsplash.it/700/654?image=621" />
      <img src="https://unsplash.it/700/500?image=423" />
      <img src="https://unsplash.it/1000/654?image=930" />
      <img src="https://unsplash.it/700/950?image=1045" />

      <div class="lightbox">
        <div class="title"></div>
        <div class="filter"></div>
        <div class="arrowr"></div>
        <div class="arrowl"></div>
        <div class="close"></div>
      </div>
    </div>
  </section>
</main>
<!-- Masonry -->
<script src="js/masonry.js"></script>

    *, *:before, *:after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100vh;
}

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

h1 {
  padding: 50px 0;
  font-weight: 400;
  text-align: center;
}

p {
  margin: 0 0 20px;
  line-height: 1.5;
}

main {
  min-width: 320px;
  max-width: 90%;
  padding: 50px;
  margin: 0 auto;
  background: #fff;
}

section {
  display: none;
  padding: 20px 0 0;
  border-top: 1px solid #ddd;
}

#tab1, #tab2, #tab3, #tab4 {
  display: none;
}

label {
  display: inline-block;
  margin: 0 0 -1px;
  padding: 15px 25px;
  font-weight: 600;
  text-align: center;
  color: #bbb;
  border: 1px solid transparent;
}

label:before {
  font-family: fontawesome;
  font-weight: normal;
  margin-right: 10px;
}

label[for*='1']:before { content: '\f030'; }
label[for*='2']:before { content: '\f007'; }
label[for*='3']:before { content: '\f003'; }
label[for*='4']:before { content: '\f02d'; }

label:hover {
  color: #888;
  cursor: pointer;
}

input:checked + label {
  color: #555;
  border: 1px solid #ddd;
  border-top: 2px solid orange;
  border-bottom: 1px solid #fff;
}

#tab1:checked ~ #content1,
#tab2:checked ~ #content2,
#tab3:checked ~ #content3,
#tab4:checked ~ #content4 {
  display: block;
}

#content1 {
    column-width: 300px;
    padding-top: 5%;
}

#content2, #content3, #content4 {
    column-width: 600px;
    padding-top: 5%;
}

#content2 img {
    width: 50%;
    box-shadow: 10px 10px 5px grey;
    margin-bottom: 3em;
}

@media screen and (max-width: 650px) {
  label {
    font-size: 0;
  }
  label:before {
    margin: 0;
    font-size: 18px;
  }

  #content2 img {
  width: 100%;
  }
}

@media screen and (max-width: 400px) {
  label {
    padding: 15px;
  }
}

/*Masonry Gallery*/

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

body {
  margin: 0;

}

h1 {
  font-weight: 100;
  margin: 0;
}

section {
  column-width: 300px;
  column-gap: 5px;
  padding: 5px;
}

section img {
  width: 100%;
  cursor: pointer;
}

.lightbox {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  display: none;
  background: #7f8c8d;
  perspective: 1000;
}

.filter {
  position: absolute;
  width: 100%;
  height: 100%;
  filter: blur(20px);
  opacity: 0.5;
  background-position: center;
  background-size: cover;
}

.lightbox img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotateY(0deg);
  max-height: 95vh;
  max-width: calc(95vw - 100px);
  transition: 0.8s cubic-bezier(0.7, 0, 0.4, 1);
  transform-style: preserve-3d;
}


/*.lightbox:hover img{
  transform: translate(-50%, -50%) rotateY(180deg);
}*/

[class^="arrow"] {
  height: 200px;
  width: 50px;
  background: rgba(0, 0, 0, 0.4);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
}

[class^="arrow"]:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  width: 15px;
  height: 15px;
}

.arrowr {
  right: 0;
}

.arrowr:after {
  border-right: 1px solid white;
  border-bottom: 1px solid white;
}

.arrowl {
  left: 0;
}

.arrowl:after {
  border-left: 1px solid white;
  border-top: 1px solid white;
}

.close {
  position: absolute;
  right: 0;
  width: 50px;
  height: 50px;
  background: rgba(0, 0, 0, 0.4);
  margin: 20px;
  cursor: pointer;
}

.close:after,
.close:before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1px;
  height: 100%;
  background: #e74c3c;
}

.close:after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

    .close:before {
      transform: translate(-50%, -50%) rotate(45deg);
    }

    .title {
      font-size: 20px;
      color: #000;
      z-index: 1000;
      position: absolute;
      top: 0;
      left: 0;
    }


    $(window).load(function() {

  $("section img").click(function() {
    $(".lightbox").fadeIn(300);
    $(".lightbox").append("<img src='" + $(this).attr("src") + "' alt='" + $(this).attr("alt") + "' />");
    $(".filter").css("background-image", "url(" + $(this).attr("src") + ")");
    /*$(".title").append("<h1>" + $(this).attr("alt") + "</h1>");*/
    $("html").css("overflow", "hidden");
    if ($(this).is(":last-child")) {
      $(".arrowr").css("display", "none");
      $(".arrowl").css("display", "block");
    } else if ($(this).is(":first-child")) {
      $(".arrowr").css("display", "block");
      $(".arrowl").css("display", "none");
    } else {
      $(".arrowr").css("display", "block");
      $(".arrowl").css("display", "block");
    }
  });
  $(".close").click(function() {
    $(".lightbox").fadeOut(300);
    $("h1").remove();
    $(".lightbox img").remove();
    $("html").css("overflow", "auto");
  });

  $(document).keyup(function(e) {
    if (e.keyCode == 27) {
      $(".lightbox").fadeOut(300);
      $(".lightbox img").remove();
      $("html").css("overflow", "auto");
    }
  });

  $(".arrowr").click(function() {
    var imgSrc = $(".lightbox img").attr("src");
    var search = $("section").find("img[src$='" + imgSrc + "']");
    var newImage = search.next().attr("src");
    /*$(".lightbox img").attr("src", search.next());*/
    $(".lightbox img").attr("src", newImage);
    $(".filter").css("background-image", "url(" + newImage + ")");

    if (!search.next().is(":last-child")) {
      $(".arrowl").css("display", "block");
    } else {
      $(".arrowr").css("display", "none");
    }
  });

  $(".arrowl").click(function() {
    var imgSrc = $(".lightbox img").attr("src");
    var search = $("section").find("img[src$='" + imgSrc + "']");
    var newImage = search.prev().attr("src");
    /*$(".lightbox img").attr("src", search.next());*/
    $(".lightbox img").attr("src", newImage);
    $(".filter").css("background-image", "url(" + newImage + ")");

    if (!search.prev().is(":first-child")) {
      $(".arrowr").css("display", "block");
    } else {
      $(".arrowl").css("display", "none");
    }
  });

});

I can't explain why your fixed element is shifted like that, but this fixes it:我无法解释为什么您的固定元素会这样移动,但这可以解决它:

.lightbox {
    ...
    left: 0;
}

Demo演示

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

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