关闭灯箱时,是否有不退回到顶部的方法?

时间:2019-04-25 10:32:35

标签: javascript jquery jquery-plugins

我正在使用this ScalableLightbox jQuery plugin。当我关闭灯箱时,页面会滚动回到顶部。有办法防止这种情况吗?您可以通过plugin's examples看到相同的行为。

我尝试使用close函数,但是什么也没发生:

$.ScalableLightbox("close", function() {
});

关闭灯箱后,我只是想停留在页面上的位置。
我该如何实现?

这是一个演示:

$(function() {

  // initialize ScalableLightbox
  $.ScalableLightbox({
    // show what's happening in
    // the debugger console
    debug: true,

    // define the path for all
    // resources (images):
    baseImgPath: 'https://www.scalable-lightbox.com/assets/img/lightbox/',

    // define data structure via API
    api: 'https://www.scalable-lightbox.com/assets/api/data.json',

    // index module setting
    index: {
      // set index layout to masonry
      layout: "masonry",
      thumb: {
        // use the number caption (default),
        // change the number format and
        // position it on the top
        caption: "number",
        captionNumberFmt: "Image %n%",
        captionPosition: "top"
      }
    },

    // lightbox module setting
    lightbox: {
      img: {
        // we display the number in the left
        // caption and change the number format
        captionLeft: "number",
        captionNumberFmt: "%n% of %total%",
        // we do not use a caption in the center
        captionCenter: "none",
        // we use the link to the index module
        // on the right and change the link text
        captionRight: "index",
        captionIndexTxt: "Back to Overview",
        // we position the caption container on
        // top, as we did in the index module
        captionPosition: "above",
        captionVerticalMargin: 10
      }
    }
  });



  // open the index module via the
  // aforementioned text links
  $("#show-canyon-house").click(function(e) {

    // prevent the default anchor behavior
    e.preventDefault();

    // open the lightbox module
    $.ScalableLightbox("open", {
      module: "index",
      deck: 1
    });

  });

  $("#show-italpromo").click(function(e) {

    // prevent the default anchor behavior
    e.preventDefault();

    // open the lightbox module
    $.ScalableLightbox("open", {
      module: "index",
      deck: 2
    });

  });

});
body {
  background: #000;
  color: #fff;
}

body .container {
  margin: 40px auto;
  width: 360px;
  padding: 0 20px;
}

.container a,
.container a:visited {
  color: #aaa;
  border-bottom: 1px solid #aaa;
  text-decoration: none;
}

.container a:focus,
.container a:hover,
.container a:active {
  color: #fff;
  border-bottom: 0;
}

.intro-item {
  margin-bottom: 70px;
}

.intro-item h2 {
  text-align: center;
  font-size: 18px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.intro-item p {
  font-family: Times, serif;
  font-size: 20px;
  line-height: 25px;
  text-indent: 25px;
  margin: 0;
}


/***************************/


/* plugin overwrite styles */


/***************************/

.sl-index-overlay,
.sl-lightbox-overlay {
  background: #000;
  opacity: 1;
}


/* we change the item overlay to a white and reduce
the opacity to 0.4 */

.sl-index-item-overlay {
  background: #fff;
  opacity: 0.4;
}


/* the index caption should be black, half transparent
with the text aligned to the left and have a top/bottom
padding */

.sl-index-item-caption {
  background: #000;
  padding: 10px 0;
  color: #fff;
  text-align: left;
  opacity: 0.7;
}


/* change the link color for the lightbox captions */

.sl-lightbox-caption-container a,
.sl-lightbox-caption-container a:visited {
  color: #fff;
}

.sl-lightbox-caption-container a:hover {
  border: 0;
  color: #aaa;
}


/* we over extend the left and right arrows, so that
navigation outside of the lightbox container is
also possible */

.sl-lightbox-cursor.left {
  left: -50%;
  width: 100%;
}

.sl-lightbox-cursor.right {
  right: -50%;
  width: 100%;
}


/**** white cursors ****/


/* index module */

.sl-index-wrapper {
  cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-close.png'), url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-close.cur'), crosshair;
}

.sl-index-item-indicator {
  background: url('https://www.scalable-lightbox.com/assets/cursors/white/loader.gif') top left no-repeat;
  background-size: 16px 16px;
}

.lt-ie9 .sl-index-item-indicator {
  background: url('https://www.scalable-lightbox.com/assets/cursors/white/loader-small.gif') top left no-repeat;
}


/* lightbox module */

.sl-lightbox-wrapper {
  cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-close.png'), url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-close.cur'), crosshair;
}

.sl-lightbox-item-indicator {
  background: url('https://www.scalable-lightbox.com/assets/cursors/white/loader.gif') top left no-repeat;
  background-size: 16px 16px;
}

.lt-ie9 .sl-lightbox-item-indicator {
  background: url('https://www.scalable-lightbox.com/assets/cursors/white/loader-small.gif') top left no-repeat;
}

.sl-lightbox-cursor {
  background: url('https://www.scalable-lightbox.com/assets/cursors/white/blank.gif') 0 0 repeat;
}

.sl-lightbox-cursor.left {
  cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-left.png'), url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-left.cur'), w-resize;
}

.sl-lightbox-cursor.right {
  cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-right.png'), url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-right.cur'), e-resize;
}


/* retina optimization */

@media (min-resolution: 192dpi),
(-webkit-min-device-pixel-ratio: 2),
(min--moz-device-pixel-ratio: 2),
(-o-min-device-pixel-ratio: 2/1),
(min-device-pixel-ratio: 2),
(min-resolution: 2dppx) {
  .sl-index-wrapper,
  .sl-lightbox-wrapper {
    cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-close-retina.png'), crosshair;
  }
  .sl-lightbox-cursor.left {
    cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-left-retina.png'), w-resize;
  }
  .sl-lightbox-cursor.right {
    cursor: url('https://www.scalable-lightbox.com/assets/cursors/white/cursor-right-retina.png'), e-resize;
  }
}
<link href="https://www.scalable-lightbox.com/assets/jquery.scalable-lightbox.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://www.scalable-lightbox.com/assets/js/jquery.hammer-full.min.js"></script>
<script src="https://www.scalable-lightbox.com/assets/js/masonry.pkgd.min.js"></script>
<script src="https://www.scalable-lightbox.com/assets/jquery.scalable-lightbox.js"></script>

<div class="container">

  <div class="intro-item">
    <h2>Canyon House</h2>
    <p>
      A private residence based on a complex three-dimensional map of interlocking space types. This commission involved the renovation of a building which itself has several additions dating back to the 1960s. Located inside the Appia Antica Park on the outskirts
      of Rome, the building serves as the clients’ main residence, and is a space both for work and relaxation.
    </p>
    <p>
      The design uses vertical axes to section <a href="#" id="show-canyon-house">the building</a> into different space types including service areas, distribution areas, main quarters and outdoor areas, establishing a specific spatial and functional
      sequence as the owners move throughout the building.
    </p>
    <p>
      In addition, the horizontal sequence of floor levels differentiates zones for sleeping, living and work. These horizontal and vertical planes create a three-dimensional map for the house and its functions.
    </p>
  </div>

  <div class="intro-item">
    <h2>Italpromo &amp; Libardi Associati Headquarters</h2>
    <p>
      A new headquarters for the well&dash;known Italian communications agency Italpromo &amp; Libardi Associati in a converted school building in Ostiense, Rome.
    </p>
    <p>
      Ostiense is one of the few remaining industrial areas on the edge of Rome’s historic city centre and is currently undergoing extensive architectural and social regeneration. The brief for <a href="#" id="show-italpromo">this project</a> was to transform
      an existing building without losing its unique character and retaining its original listed façade.
    </p>
    <p>
      Labics’ main objective was to introduce new functions into the shell of the existing building, creating innovative ways of using the space based on the complex spatial, functional and social relationships within the contemporary workplace. The aim was
      to find the right balance between individual and shared spaces, between production and social areas.
    </p>
  </div>

</div>

View on CodePen

0 个答案:

没有答案