如何向 Lightbox 中的图像添加第二个水平滚动条?

问题描述 投票:0回答:1

我正在尝试向 Lightbox 生成的弹出图像添加第二个水平滚动条。我知道滚动条并不是 Lightbox 的预期用途。 Lightbox 中的图像传统上受窗口大小的限制。但是,滚动条是客户想要的,现在,图像底部有一个滚动条,我想在图像顶部添加第二个滚动条。

在我的jsfiddle中https://jsfiddle.net/mrgfvwd1/1/弹出图像底部有一个滚动条(当然,我们忽略jsfiddle添加的水平和垂直滚动条)。

我想在图像上方添加第二个水平线,我正在遵循之前的答案表格顶部和底部的水平滚动条及其jsfiddlehttps://jsfiddle.net/TBnqw/1/

但是我无法弄清楚在 Lightbox 中使用哪个 div 或容器来定位,无论是使用将滚动条“回显”到顶部的 jQuery 函数(在上面问题的可接受答案中),还是纯 CSS 解决方案。我可以使用 jQuery 附加或前置将 div .wrapper1 添加到 Lightbox 的标记输出吗?

我正在小提琴中本地加载 Lightbox 脚本,以防需要修改。我知道这不是一个好主意,但最坏的情况下,我们可以。

HTML:

<a href="https://fastly.picsum.photos/id/11/2500/1667.jpg?hmac=xxjFJtAPgshYkysU_aqx2sZir-kIOjNR9vx0te7GycQ" data-lightbox="1">
<img src="https://fastly.picsum.photos/id/11/2500/1667.jpg?hmac=xxjFJtAPgshYkysU_aqx2sZir-kIOjNR9vx0te7GycQ" width="300">
</a>

CSS:

body.lb-disable-scrolling {
  overflow: hidden;
}

.center {
  text-align: center;
}

.new-div {
  overflow-x: scroll;
  overflow-y: hidden;
  height: 20px;
  background-color: red;
}

.lightboxOverlay {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 9999;
  background-color: black;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=80);
  opacity: 0.8;
  display: none;
}

.lightbox {
  position: absolute;
  left: 0;
  width: 100%;
  z-index: 10000;
  text-align: center;
  line-height: 0;
  font-weight: normal;
  outline: none;
}

.lightbox .lb-image {
  display: block;
  width: 100% !important;
  height: auto !important;
  border-radius: 3px;
  border: 4px solid white;
}

.lightbox a img {
  border: none;
}

.lb-outerContainer {
  position: relative;
  *zoom: 1;
  margin: 0 auto;
  border-radius: 4px;
  background-color: white;
  margin-top: 30px;
}

.lb-outerContainer:after {
  content: "";
  display: table;
  clear: both;
}

.lb-loader {
  position: absolute;
  top: 43%;
  left: 0;
  height: 25%;
  width: 100%;
  text-align: center;
  line-height: 0;
}

.lb-cancel {
  display: block;
  width: 32px;
  height: 32px;
  margin: 0 auto;
  background: url(../images/loading.gif) no-repeat;
}

.lb-nav {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  z-index: 10;
}

.lb-container > .nav {
  left: 0;
}

.lb-nav a {
  outline: none;
  background-image: url("data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
}

.lb-prev,
.lb-next {
  height: 100%;
  cursor: pointer;
  display: block;
}

.lb-nav a.lb-prev {
  width: 20%;
  left: 0;
  float: left;
  background: url(../images/prev.png) left 48% no-repeat;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
  opacity: 0;
  -webkit-transition: opacity 0.6s;
  -moz-transition: opacity 0.6s;
  -o-transition: opacity 0.6s;
  transition: opacity 0.6s;
}

.lb-nav a.lb-prev:hover {
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  opacity: 1;
}

.lb-nav a.lb-next {
  width: 20%;
  right: 0;
  float: right;
  background: url(../images/next.png) right 48% no-repeat;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=0);
  opacity: 0;
  -webkit-transition: opacity 0.6s;
  -moz-transition: opacity 0.6s;
  -o-transition: opacity 0.6s;
  transition: opacity 0.6s;
}

.lb-nav a.lb-next:hover {
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  opacity: 1;
}

.lb-dataContainer {
  margin: 0 auto;
  padding-top: 5px;
  *zoom: 1;
  width: 100%;
  border-bottom-left-radius: 4px;
  border-bottom-right-radius: 4px;
}

.lb-dataContainer:after {
  content: "";
  display: table;
  clear: both;
}

.lb-data {
  padding: 0 4px;
  color: #ccc;
}

.lb-data .lb-details {
  width: 85%;
  float: left;
  text-align: left;
  line-height: 1.1em;
}

.lb-data .lb-caption {
  font-size: 13px;
  font-weight: bold;
  line-height: 1em;
}

.lb-data .lb-caption a {
  color: #4ae;
}

.lb-data .lb-number {
  display: block;
  clear: left;
  padding-bottom: 1em;
  font-size: 12px;
  color: #999999;
}

.lb-data .lb-close {
  display: block;
  float: right;
  width: 30px;
  height: 30px;
  background: url(../images/close.png) top right no-repeat;
  text-align: right;
  outline: none;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70);
  opacity: 0.7;
  -webkit-transition: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  transition: opacity 0.2s;
}

.lb-data .lb-close:hover {
  cursor: pointer;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100);
  opacity: 1;
}
.lb-linkContainer {
  position: relative;
}

#lightbox {
  overflow-x: auto;
  cursor: pointer;
}

#lightbox.active {
  cursor: grabbing;
}
#lightbox::-webkit-scrollbar {
  display: none;
}
.lb-data .lb-close {
  display: block;
  float: right;
  width: 30px;
  height: 30px;
  background: url(../images/close.png) top right no-repeat;
  text-align: right;
  outline: none;
  filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70);
  opacity: 0.7;
  -webkit-transition: opacity 0.2s;
  -moz-transition: opacity 0.2s;
  -o-transition: opacity 0.2s;
  transition: opacity 0.2s;
  position: absolute;
  top: 10px;
  right: 20px;
}
.lb-closeContainer {
  background: rgba(0, 0, 0, 0.5);
  left: 0;
  width: 100%;
  height: 50px;
  position: fixed;
  top: 0;
  z-index: 99;
}
.admin-bar .lb-closeContainer {
  top: 32px;
}
.lb-closeContainer:before {
  content: "<-- Esc to close image. Use scroll bar to move left and right on wide images -->";
  color: white;
  font-size: 18px;
  position: relative;
  top: 25px;
}
javascript jquery css lightbox2
1个回答
0
投票

可以添加

      <div id="upper-scroll" style="width:100%;height:10px;background-color:red;overflow-x:scroll;"><div id="inner-scroll" style="height:1px;"></div></div>

到图像上方的灯箱,然后添加这些卷轴:

$(function () {
  $("#upper-scroll").scroll(function () {
    $("#lightbox").scrollLeft($("#upper-scroll").scrollLeft())
  })
  $("#lightbox").scroll(function () {
    $("#upper-scroll").scrollLeft($("#lightbox").scrollLeft())
  })
})

您基本上为

scroll
创建一个
#upper-scroll
事件,以便将类似的
scroll
作为事件应用到
#lightbox
,反之亦然。最后,您需要确保您的卷轴大小相似,因此添加以下内容:

$("#inner-scroll").css("width", $(".lb-image").width());

showImage

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.