如何在bootstrap中添加prev和next链接以更改bootstrap模式中的图像

时间:2017-05-20 10:29:13

标签: jquery twitter-bootstrap bootstrap-modal

大家好我想尝试在bootstrap模式弹出窗口中显示图像和视频,使用上一页和下一页链接获取下一张图像,或者我想返回查看图像。

这完全适用于以下代码,但此处箭头可以向前或向后移动图像。

但我不想要那个箭头而不是我需要上一个和下一个链接更改图像

我引用此链接http://michaelsoriano.com/next-and-previous-buttons-bootstrap-photo-gallery/添加上一个和下一个链接,而不是箭头,它不起作用

以同样的方式显示视频我必须做的更改

(function($) {
  "use strict";
  $.fn.bsPhotoGallery = function(options) {

    var settings = $.extend({}, $.fn.bsPhotoGallery.defaults, options);
    var id = generateId();
    var classesString = settings.classes;
    var classesArray = classesString.split(" ");
    var clicked = {};

    function getCurrentUl() {
      return 'ul[data-bsp-ul-id="' + clicked.ulId + '"][data-bsp-ul-index="' + clicked.ulIndex + '"]';
    }

    function generateId() {
      //http://fiznool.com/blog/2014/11/16/short-id-generation-in-javascript/
      var ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      var ID_LENGTH = 4;
      var out = '';
      for (var i = 0; i < ID_LENGTH; i++) {
        out += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));
      }
      return 'bsp-' + out;
    }

    function createModalWrap() {

      if ($('#bsPhotoGalleryModal').length !== 0) {
        return false;
      }

      var modal = '';
      modal += '<div class="modal fade" id="bsPhotoGalleryModal" tabindex="-1" role="dialog"';
      modal += 'aria-labelledby="myModalLabel" aria-hidden="true">';
      modal += '<div class="modal-dialog modal-lg"><div class="modal-content">';
      modal += '<div class="modal-body"></div></div></div></div>';
      $('body').append(modal);

    }

    function showHideControls() {
      var total = $(getCurrentUl() + ' li[data-bsp-li-index]').length;

      if (total === clicked.nextImg) {
        $('a.next').hide();
      } else {
        $('a.next').show()
      }
      if (clicked.prevImg === -1) {
        $('a.previous').hide();
      } else {
        $('a.previous').show()
      }
    }

    function showModal() {

      var src = $(this).find('img').attr('src');
      var largeImg = $(this).find('img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }
      var index = $(this).attr('data-bsp-li-index');
      var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
      var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
      var theImg = $(this).find('img');
      var pText = $(this).find('.text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      clicked.img = src;
      clicked.prevImg = parseInt(index) - parseInt(1);
      clicked.nextImg = parseInt(index) + parseInt(1);
      clicked.ulIndex = ulIndex;
      clicked.ulId = ulId;


      $('#bsPhotoGalleryModal').modal();

      var html = '';
      var img = '<img src="' + clicked.img + '" class="img-responsive"/>';

      html += img;
      html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
      html += '<div class="bsp-text-container">';

      if (alt !== null) {
        html += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        html += '<p class="pText">' + pText + '</p>'
      }
      html += '</div>';
      html += '<a class="bsp-controls next" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.nextImg) + '"><span class="' + settings.iconRight + '"></span></a>';
      html += '<a class="bsp-controls previous" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.prevImg) + '"><span class="' + settings.iconLeft + '"></span></a>';

      $('#bsPhotoGalleryModal .modal-body').html(html);
      $('.bsp-close').on('click', closeModal);
      showHideControls();
    }

    function closeModal() {
      $('#bsPhotoGalleryModal').modal('hide');
    }

    function nextPrevHandler() {

      var ul = $(getCurrentUl());
      var index = $(this).attr('href');

      var src = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('src');
      var largeImg = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }

      var pText = ul.find('li[data-bsp-li-index="' + index + '"] .text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var theImg = ul.find('li[data-bsp-li-index="' + index + '"] img');
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      $('#bsPhotoGalleryModal .modal-body img').attr('src', src);
      var txt = '';
      if (alt !== null) {
        txt += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        txt += '<p class="pText">' + pText + '</p>'
      }

      $('.bsp-text-container').html(txt);

      clicked.prevImg = parseInt(index) - 1;
      clicked.nextImg = parseInt(clicked.prevImg) + 2;

      if ($(this).hasClass('previous')) {
        $(this).attr('href', clicked.prevImg);
        $('a.next').attr('href', clicked.nextImg);
      } else {
        $(this).attr('href', clicked.nextImg);
        $('a.previous').attr('href', clicked.prevImg);
      }
      // console.log(clicked);
      showHideControls();
      return false;
    }

    function clearModalContent() {
      $('#bsPhotoGalleryModal .modal-body').html('');
      clicked = {};
    }

    function insertClearFix(el, x) {
      var index = (x + 1);
      $.each(classesArray, function(e) {
        switch (classesArray[e]) {
          //large
          case "col-lg-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-5":
          case "col-lg-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
            //medium
          case "col-md-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-5":
          case "col-md-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
            //small
          case "col-sm-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-5":
          case "col-sm-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
            //x-small
          case "col-xs-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-5":
          case "col-xs-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
        }
      });
    }


    this.each(function(i) {
      //ul
      var items = $(this).find('li');
      $(this).attr('data-bsp-ul-id', id);
      $(this).attr('data-bsp-ul-index', i);

      items.each(function(x) {
        var theImg = $(this).find('img');
        insertClearFix(this, x);
        $(this).addClass(classesString);
        $(this).attr('data-bsp-li-index', x);
        theImg.addClass('img-responsive');
        if (settings.fullHeight) {
          theImg.wrap('<div class="imgWrapper"></div>')
        }
        if (settings.hasModal === true) {
          $(this).addClass('bspHasModal');
          $(this).on('click', showModal);
        }
      });
    })

    if (settings.hasModal === true) {
      //this is for the next / previous buttons
      $(document).on('click', 'a.bsp-controls[data-bsp-id="' + id + '"]', nextPrevHandler);
      $(document).on('hidden.bs.modal', '#bsPhotoGalleryModal', clearModalContent);
      //start init methods
      createModalWrap();
    }

    return this;
  };















  /*defaults*/
  $.fn.bsPhotoGallery.defaults = {
    'classes': 'col-lg-2 col-md-2 col-sm-3 col-xs-4',
    'hasModal': true,
    'fullHeight': true,
    'iconClose': 'glyphicon glyphicon-remove-circle',
    'iconLeft': 'glyphicon glyphicon-chevron-left',
    'iconRight': 'glyphicon glyphicon-chevron-right'
  }


}(jQuery));
#bsPhotoGalleryModal .modal-content {
  border-radius: 0;
}

#bsPhotoGalleryModal .modal-dialog img {
  text-align: center;
  margin: 0 auto;
  width: 100%;
}

#bsPhotoGalleryModal .modal-body {
  padding: 0px !important;
}

#bsPhotoGalleryModal .bsp-close {
  position: absolute;
  right: -14px;
  top: -11px;
  font-size: 30px;
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}

#bsPhotoGalleryModal .bsp-close:hover {
  cursor: pointer;
  opacity: .6;
  text-shadow: none;
}

.bspHasModal {
  cursor: pointer;
}

.bspHasModal .text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imgWrapper {
  overflow: hidden;
  max-height: 99px;
}

a.bsp-controls,
a.bsp-controls:visited,
a.bsp-controls:active {
  position: absolute;
  top: 44%;
  font-size: 26px;
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}

a.bsp-controls.next {
  right: -10px;
}

a.bsp-controls.previous {
  left: -10px;
}

a.bsp-controls:hover {
  opacity: .6;
  text-shadow: none;
}

.bsp-text-container {
  clear: both;
  display: block;
  padding-bottom: 5px;
}

#bsPhotoGalleryModal h6 {
  margin-bottom: 0;
  font-weight: bold;
  color: #000;
  font-size: 14px;
  padding-left: 12px;
  padding-right: 12px;
  margin-bottom: 5px;
}

#bsPhotoGalleryModal .pText {
  font-size: 11px;
  margin-bottom: 0px;
  padding: 0 12px 5px;
}

@media screen and (max-width: 380px) {
  .col-xxs-12 {
    width: 100%;
  }
  .col-xxs-12 img {
    width: 100%;
  }
}
**Html page**


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>Bootstrap Photo Gallery Demo</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <link href="jquery.bsPhotoGallery.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="jquery.bsPhotoGallery.js"></script>

  <script>
    $(document).ready(function() {
      $('ul.first').bsPhotoGallery({
        "classes": "col-lg-2 col-md-4 col-sm-3 col-xs-4 col-xxs-12",
        "hasModal": true,
        // "fullHeight" : false
      });
    });
  </script>
</head>
<style>
  @import url(https://fonts.googleapis.com/css?family=Bree+Serif);
  body {
    background: #ebebeb;
  }
  
  ul {
    padding: 0 0 0 0;
    margin: 0 0 40px 0;
  }
  
  ul li {
    list-style: none;
    margin-bottom: 10px;
  }
  
  .text {
    /*font-family: 'Bree Serif';*/
    color: #666;
    font-size: 11px;
    margin-bottom: 10px;
    padding: 12px;
    background: #fff;
  }
</style>

<body>
  <div class="container">
    <div class="row" style="text-align: center; border-bottom: 1px dashed #ccc; padding: 0 0 20px 0; margin-bottom: 40px;">
      <h3 style="font-family: 'Bree Serif', arial; font-weight: bold; font-size: 30px;">
        <a style="text-decoration: none; color: #666;" href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Bootstrap
        					Photo Gallery jQuery plugin <span style="color: red;">Demo</span>
        				</a>
      </h3>
      <p>
        Resize your browser and watch the gallery adapt to the view port size. Clicking on an image will activate the Modal. Click <strong><a
        					style="color: red"
        					href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Here</a></strong> to go back to the tutorial
      </p>
    </div>

    <ul class="row first">

      <li><img alt="Rocking the night away" src="http://demo.michaelsoriano.com/images/photodune-3552322-insurance-xs.jpg"></li>

      <li>
        <img alt="Food Explosion" src="http://demo.michaelsoriano.com/images/photodune-3807845-food-s.jpg">
        <div class="text">Eiusmod tempor enim ad minim veniam</div>
      </li>
      <li>
        <img alt="Office worker sad" src="http://demo.michaelsoriano.com/images/photodune-3835655-down-office-worker-xs.jpg">
        <div class="text">Ut enim ad minim veniam</div>
      </li>

      <li>
        <img alt="" src="http://demo.michaelsoriano.com/images/photodune-4619216-ui-control-knob-regulators-xs.jpg">
        <div class="text">Do eiusmod tempor</div>
      </li>



    </ul>
  </div>
  <!-- /container -->

  <body>

</html>

另一种方式 https://jsfiddle.net/vrgy0vs2/

3 个答案:

答案 0 :(得分:1)

删除默认bsControls后,您可以定义自己的控件。请参阅下面使用bootstrap网格实现的示例。

&#13;
&#13;
(function($) {
  "use strict";
  $.fn.bsPhotoGallery = function(options) {

    var settings = $.extend({}, $.fn.bsPhotoGallery.defaults, options);
    var id = generateId();
    var classesString = settings.classes;
    var classesArray = classesString.split(" ");
    var clicked = {};

    function getCurrentUl() {
      return 'ul[data-bsp-ul-id="' + clicked.ulId + '"][data-bsp-ul-index="' + clicked.ulIndex + '"]';
    }

    function generateId() {
      //http://fiznool.com/blog/2014/11/16/short-id-generation-in-javascript/
      var ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      var ID_LENGTH = 4;
      var out = '';
      for (var i = 0; i < ID_LENGTH; i++) {
        out += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));
      }
      return 'bsp-' + out;
    }

    function createModalWrap() {

      if ($('#bsPhotoGalleryModal').length !== 0) {
        return false;
      }

      var modal = '';
      modal += '<div class="modal fade" id="bsPhotoGalleryModal" tabindex="-1" role="dialog"';
      modal += 'aria-labelledby="myModalLabel" aria-hidden="true">';
      modal += '<div class="modal-dialog modal-lg"><div class="modal-content">';
      modal += '<div class="modal-body"></div></div></div></div>';
      $('body').append(modal);

    }

    function showHideControls() {
      var total = $(getCurrentUl() + ' li[data-bsp-li-index]').length;

      if (total === clicked.nextImg) {
        $('a.next').hide();
      } else {
        $('a.next').show()
      }
      if (clicked.prevImg === -1) {
        $('a.previous').hide();
      } else {
        $('a.previous').show()
      }
    }

    function showModal() {

      var src = $(this).find('img').attr('src');
      var largeImg = $(this).find('img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }
      var index = $(this).attr('data-bsp-li-index');
      var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
      var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
      var theImg = $(this).find('img');
      var pText = $(this).find('.text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      clicked.img = src;
      clicked.prevImg = parseInt(index) - parseInt(1);
      clicked.nextImg = parseInt(index) + parseInt(1);
      clicked.ulIndex = ulIndex;
      clicked.ulId = ulId;


      $('#bsPhotoGalleryModal').modal();

      var html = "";
      var img = '<img src="' + clicked.img + '" class="img-responsive"/>';
      html += img;
      html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
      html += "<div class='row'><div class='text-left col-md-2 col-lg-2 col-sm-2 col-xs-2'>";
      html += '<a class="bsp-controls next" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.nextImg) + '"><span>Prev</span></a>';
      html += "</div><div class='col-md-8 col-lg-8 col-sm-8 col-xs-8'>";
      html += '<div class="bsp-text-container">';

      if (alt !== null) {
        html += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        html += '<p class="pText">' + pText + '</p>'
      }
      html += '</div>';
      html += "</div><div class='text-right col-md-2 col-lg-2 col-sm-2 col-xs-2'>";
      html += '<a class="bsp-controls previous" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.prevImg) + '"><span>Next</span></a>';
      html += "</div></div>";


      $('#bsPhotoGalleryModal .modal-body').html(html);
      $('.bsp-close').on('click', closeModal);
      showHideControls();
    }

    function closeModal() {
      $('#bsPhotoGalleryModal').modal('hide');
    }

    function nextPrevHandler() {

      var ul = $(getCurrentUl());
      var index = $(this).attr('href');

      var src = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('src');
      var largeImg = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }

      var pText = ul.find('li[data-bsp-li-index="' + index + '"] .text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var theImg = ul.find('li[data-bsp-li-index="' + index + '"] img');
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      $('#bsPhotoGalleryModal .modal-body img').attr('src', src);
      var txt = '';
      if (alt !== null) {
        txt += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        txt += '<p class="pText">' + pText + '</p>'
      }

      $('.bsp-text-container').html(txt);

      clicked.prevImg = parseInt(index) - 1;
      clicked.nextImg = parseInt(clicked.prevImg) + 2;

      if ($(this).hasClass('previous')) {
        $(this).attr('href', clicked.prevImg);
        $('a.next').attr('href', clicked.nextImg);
      } else {
        $(this).attr('href', clicked.nextImg);
        $('a.previous').attr('href', clicked.prevImg);
      }
      // console.log(clicked);
      showHideControls();
      return false;
    }

    function clearModalContent() {
      $('#bsPhotoGalleryModal .modal-body').html('');
      clicked = {};
    }

    function insertClearFix(el, x) {
      var index = (x + 1);
      $.each(classesArray, function(e) {
        switch (classesArray[e]) {
          //large
          case "col-lg-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-5":
          case "col-lg-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
            //medium
          case "col-md-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-5":
          case "col-md-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
            //small
          case "col-sm-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-5":
          case "col-sm-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
            //x-small
          case "col-xs-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-5":
          case "col-xs-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
        }
      });
    }


    this.each(function(i) {
      //ul
      var items = $(this).find('li');
      $(this).attr('data-bsp-ul-id', id);
      $(this).attr('data-bsp-ul-index', i);

      items.each(function(x) {
        var theImg = $(this).find('img');
        insertClearFix(this, x);
        $(this).addClass(classesString);
        $(this).attr('data-bsp-li-index', x);
        theImg.addClass('img-responsive');
        if (settings.fullHeight) {
          theImg.wrap('<div class="imgWrapper"></div>')
        }
        if (settings.hasModal === true) {
          $(this).addClass('bspHasModal');
          $(this).on('click', showModal);
        }
      });
    })

    if (settings.hasModal === true) {
      //this is for the next / previous buttons
      $(document).on('click', 'a.bsp-controls[data-bsp-id="' + id + '"]', nextPrevHandler);
      $(document).on('hidden.bs.modal', '#bsPhotoGalleryModal', clearModalContent);
      //start init methods
      createModalWrap();
    }

    return this;
  };















  /*defaults*/
  $.fn.bsPhotoGallery.defaults = {
    'classes': 'col-lg-2 col-md-2 col-sm-3 col-xs-4',
    'hasModal': true,
    'fullHeight': true,
    'iconClose': 'glyphicon glyphicon-remove-circle',
    'iconLeft': 'glyphicon glyphicon-chevron-left',
    'iconRight': 'glyphicon glyphicon-chevron-right'
  }


}(jQuery));
&#13;
#bsPhotoGalleryModal .modal-content {
  border-radius: 0;
}

#bsPhotoGalleryModal .modal-dialog img {
  text-align: center;
  margin: 0 auto;
  width: 100%;
}

#bsPhotoGalleryModal .modal-body {
  padding: 0px !important;
}

#bsPhotoGalleryModal .bsp-close {
  position: absolute;
  right: -14px;
  top: -11px;
  font-size: 30px;
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}

#bsPhotoGalleryModal .bsp-close:hover {
  cursor: pointer;
  opacity: .6;
  text-shadow: none;
}

.bspHasModal {
  cursor: pointer;
}

.bspHasModal .text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imgWrapper {
  overflow: hidden;
  max-height: 99px;
}

a.bsp-controls,
a.bsp-controls:visited,
a.bsp-controls:active {
  /*position: absolute;
  top: 44%;
  font-size: 26px;*/
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}


/*a.bsp-controls.next {
  right: -10px;
}

a.bsp-controls.previous {
  left: -10px;
}*/

a.bsp-controls:hover {
  opacity: .6;
  text-shadow: none;
}


/*.bsp-text-container {
  clear: both;
  display: block;
  padding-bottom: 5px;
}*/

#bsPhotoGalleryModal h6 {
  margin-bottom: 0;
  font-weight: bold;
  color: #000;
  font-size: 14px;
  padding-left: 12px;
  padding-right: 12px;
  margin-bottom: 5px;
}

#bsPhotoGalleryModal .pText {
  font-size: 11px;
  margin-bottom: 0px;
  padding: 0 12px 5px;
}

@media screen and (max-width: 380px) {
  .col-xxs-12 {
    width: 100%;
  }
  .col-xxs-12 img {
    width: 100%;
  }
}
&#13;
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>Bootstrap Photo Gallery Demo</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <link href="jquery.bsPhotoGallery.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="jquery.bsPhotoGallery.js"></script>

  <script>
    $(document).ready(function() {
      $('ul.first').bsPhotoGallery({
        "classes": "col-lg-2 col-md-4 col-sm-3 col-xs-4 col-xxs-12",
        "hasModal": true,
        // "fullHeight" : false
      });
    });
  </script>
</head>
<style>
  @import url(https://fonts.googleapis.com/css?family=Bree+Serif);
  body {
    background: #ebebeb;
  }
  
  ul {
    padding: 0 0 0 0;
    margin: 0 0 40px 0;
  }
  
  ul li {
    list-style: none;
    margin-bottom: 10px;
  }
  
  .text {
    /*font-family: 'Bree Serif';*/
    color: #666;
    font-size: 11px;
    margin-bottom: 10px;
    padding: 12px;
    background: #fff;
  }
</style>

<body>
  <div class="container">
    <div class="row" style="text-align: center; border-bottom: 1px dashed #ccc; padding: 0 0 20px 0; margin-bottom: 40px;">
      <h3 style="font-family: 'Bree Serif', arial; font-weight: bold; font-size: 30px;">
        <a style="text-decoration: none; color: #666;" href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Bootstrap
        					Photo Gallery jQuery plugin <span style="color: red;">Demo</span>
        				</a>
      </h3>
      <p>
        Resize your browser and watch the gallery adapt to the view port size. Clicking on an image will activate the Modal. Click <strong><a
        					style="color: red"
        					href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Here</a></strong> to go back to the tutorial
      </p>
    </div>

    <ul class="row first">

      <li><img alt="Rocking the night away" src="http://demo.michaelsoriano.com/images/photodune-3552322-insurance-xs.jpg"></li>

      <li>
        <img alt="Food Explosion" src="http://demo.michaelsoriano.com/images/photodune-3807845-food-s.jpg">
        <div class="text">Eiusmod tempor enim ad minim veniam</div>
      </li>
      <li>
        <img alt="Office worker sad" src="http://demo.michaelsoriano.com/images/photodune-3835655-down-office-worker-xs.jpg">
        <div class="text">Ut enim ad minim veniam</div>
      </li>

      <li>
        <img alt="" src="http://demo.michaelsoriano.com/images/photodune-4619216-ui-control-knob-regulators-xs.jpg">
        <div class="text">Do eiusmod tempor</div>
      </li>



    </ul>
  </div>
  <!-- /container -->

  <body>

</html>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您只需要对Javascript代码进行两处更改:

替换

SELECT aerAlertID
FROM AlertEmployeeRel aer
WHERE aer.EmployeeID  IN (Select e.ID 
                          FROM Employee e
                          WHERE e.FirstName like '%$key%' or e.LastName = '%$key%' or e.MiddleName = '%$key%'
                         );

<span class="' + settings.iconRight + '"></span> with Next

向右滚动以查看包含html定义的两行替换。

您的Javascript代码

replace <span class="' + settings.iconLeft + '"></span> with Prev

答案 2 :(得分:0)

您可以查看显示Next-Prev链接实现的更新代码。

&#13;
&#13;
(function($) {
  "use strict";
  $.fn.bsPhotoGallery = function(options) {

    var settings = $.extend({}, $.fn.bsPhotoGallery.defaults, options);
    var id = generateId();
    var classesString = settings.classes;
    var classesArray = classesString.split(" ");
    var clicked = {};

    function getCurrentUl() {
      return 'ul[data-bsp-ul-id="' + clicked.ulId + '"][data-bsp-ul-index="' + clicked.ulIndex + '"]';
    }

    function generateId() {
      //http://fiznool.com/blog/2014/11/16/short-id-generation-in-javascript/
      var ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      var ID_LENGTH = 4;
      var out = '';
      for (var i = 0; i < ID_LENGTH; i++) {
        out += ALPHABET.charAt(Math.floor(Math.random() * ALPHABET.length));
      }
      return 'bsp-' + out;
    }

    function createModalWrap() {

      if ($('#bsPhotoGalleryModal').length !== 0) {
        return false;
      }

      var modal = '';
      modal += '<div class="modal fade" id="bsPhotoGalleryModal" tabindex="-1" role="dialog"';
      modal += 'aria-labelledby="myModalLabel" aria-hidden="true">';
      modal += '<div class="modal-dialog modal-lg"><div class="modal-content">';
      modal += '<div class="modal-body"></div></div></div></div>';
      $('body').append(modal);

    }

    function showHideControls() {
      var total = $(getCurrentUl() + ' li[data-bsp-li-index]').length;

      if (total === clicked.nextImg) {
        $('a.next').hide();
      } else {
        $('a.next').show()
      }
      if (clicked.prevImg === -1) {
        $('a.previous').hide();
      } else {
        $('a.previous').show()
      }
    }

    function showModal() {

      var src = $(this).find('img').attr('src');
      var largeImg = $(this).find('img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }
      var index = $(this).attr('data-bsp-li-index');
      var ulIndex = $(this).parent('ul').attr('data-bsp-ul-index');
      var ulId = $(this).parent('ul').attr('data-bsp-ul-id');
      var theImg = $(this).find('img');
      var pText = $(this).find('.text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      clicked.img = src;
      clicked.prevImg = parseInt(index) - parseInt(1);
      clicked.nextImg = parseInt(index) + parseInt(1);
      clicked.ulIndex = ulIndex;
      clicked.ulId = ulId;


      $('#bsPhotoGalleryModal').modal();

      var html = '';
      var img = '<img src="' + clicked.img + '" class="img-responsive"/>';

      html += img;
      html += '<span class="' + settings.iconClose + ' bsp-close"></span>';
      html += '<div class="bsp-text-container">';

      if (alt !== null) {
        html += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        html += '<p class="pText">' + pText + '</p>'
      }      
      html += '</div>';
      
      html += '<p style="clear: both;display: flow-root;"><a class="bsp-controls next" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.nextImg) + '"><span >Next</span></a>';
      html += '<a class="bsp-controls previous" data-bsp-id="' + clicked.ulId + '" href="' + (clicked.prevImg) + '"><span>Prev</span></a></p>';

      $('#bsPhotoGalleryModal .modal-body').html(html);
      $('.bsp-close').on('click', closeModal);
      showHideControls();
    }

    function closeModal() {
      $('#bsPhotoGalleryModal').modal('hide');
    }

    function nextPrevHandler() {

      var ul = $(getCurrentUl());
      var index = $(this).attr('href');

      var src = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('src');
      var largeImg = ul.find('li[data-bsp-li-index="' + index + '"] img').attr('data-bsp-large-src');
      if (typeof largeImg === 'string') {
        src = largeImg;
      }

      var pText = ul.find('li[data-bsp-li-index="' + index + '"] .text').html();
      var modalText = typeof pText !== 'undefined' ? pText : 'undefined';
      var theImg = ul.find('li[data-bsp-li-index="' + index + '"] img');
      var alt = typeof theImg.attr('alt') == 'string' ? theImg.attr('alt') : null;

      $('#bsPhotoGalleryModal .modal-body img').attr('src', src);
      var txt = '';
      if (alt !== null) {
        txt += '<h6>' + alt + '</h6>'
      }
      if (typeof pText !== 'undefined') {
        txt += '<p class="pText">' + pText + '</p>'
      }

      $('.bsp-text-container').html(txt);

      clicked.prevImg = parseInt(index) - 1;
      clicked.nextImg = parseInt(clicked.prevImg) + 2;

      if ($(this).hasClass('previous')) {
        $(this).attr('href', clicked.prevImg);
        $('a.next').attr('href', clicked.nextImg);
      } else {
        $(this).attr('href', clicked.nextImg);
        $('a.previous').attr('href', clicked.prevImg);
      }
      // console.log(clicked);
      showHideControls();
      return false;
    }

    function clearModalContent() {
      $('#bsPhotoGalleryModal .modal-body').html('');
      clicked = {};
    }

    function insertClearFix(el, x) {
      var index = (x + 1);
      $.each(classesArray, function(e) {
        switch (classesArray[e]) {
          //large
          case "col-lg-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
          case "col-lg-5":
          case "col-lg-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-lg-block"></li>');
            }
            break;
            //medium
          case "col-md-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
          case "col-md-5":
          case "col-md-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-md-block"></li>');
            }
            break;
            //small
          case "col-sm-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
          case "col-sm-5":
          case "col-sm-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-sm-block"></li>');
            }
            break;
            //x-small
          case "col-xs-1":
            if ($(el).next('li.clearfix').length == 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-2":
            if (index % 6 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-3":
            if (index % 4 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-4":
            if (index % 3 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
          case "col-xs-5":
          case "col-xs-6":
            if (index % 2 === 0) {
              $(el).after('<li class="clearfix visible-xs-block"></li>');
            }
            break;
        }
      });
    }


    this.each(function(i) {
      //ul
      var items = $(this).find('li');
      $(this).attr('data-bsp-ul-id', id);
      $(this).attr('data-bsp-ul-index', i);

      items.each(function(x) {
        var theImg = $(this).find('img');
        insertClearFix(this, x);
        $(this).addClass(classesString);
        $(this).attr('data-bsp-li-index', x);
        theImg.addClass('img-responsive');
        if (settings.fullHeight) {
          theImg.wrap('<div class="imgWrapper"></div>')
        }
        if (settings.hasModal === true) {
          $(this).addClass('bspHasModal');
          $(this).on('click', showModal);
        }
      });
    })

    if (settings.hasModal === true) {
      //this is for the next / previous buttons
      $(document).on('click', 'a.bsp-controls[data-bsp-id="' + id + '"]', nextPrevHandler);
      $(document).on('hidden.bs.modal', '#bsPhotoGalleryModal', clearModalContent);
      //start init methods
      createModalWrap();
    }

    return this;
  };















  /*defaults*/
  $.fn.bsPhotoGallery.defaults = {
    'classes': 'col-lg-2 col-md-2 col-sm-3 col-xs-4',
    'hasModal': true,
    'fullHeight': true,
    'iconClose': 'glyphicon glyphicon-remove-circle',
    'iconLeft': 'glyphicon glyphicon-chevron-left',
    'iconRight': 'glyphicon glyphicon-chevron-right'
  }


}(jQuery));
&#13;
#bsPhotoGalleryModal .modal-content {
  border-radius: 0;
}

#bsPhotoGalleryModal .modal-dialog img {
  text-align: center;
  margin: 0 auto;
  width: 100%;
}

#bsPhotoGalleryModal .modal-body {
  padding: 0px !important;
}

#bsPhotoGalleryModal .bsp-close {
  position: absolute;
  right: -14px;
  top: -11px;
  font-size: 30px;
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}

#bsPhotoGalleryModal .bsp-close:hover {
  cursor: pointer;
  opacity: .6;
  text-shadow: none;
}

.bspHasModal {
  cursor: pointer;
}

.bspHasModal .text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.imgWrapper {
  overflow: hidden;
  max-height: 99px;
}

a.bsp-controls,
a.bsp-controls:visited,
a.bsp-controls:active {
  position: absolute;
  top: 44%;
  font-size: 26px;
  color: #fff;
  text-shadow: 1px 1px 18px #000;
}

a.bsp-controls.next {
  right: -10px;
}

a.bsp-controls.previous {
  left: -10px;
}

a.bsp-controls:hover {
  opacity: .6;
  text-shadow: none;
}

.bsp-text-container {
  clear: both;
  display: block;
  padding-bottom: 5px;
}

#bsPhotoGalleryModal h6 {
  margin-bottom: 0;
  font-weight: bold;
  color: #000;
  font-size: 14px;
  padding-left: 12px;
  padding-right: 12px;
  margin-bottom: 5px;
}

#bsPhotoGalleryModal .pText {
  font-size: 11px;
  margin-bottom: 0px;
  padding: 0 12px 5px;
}

@media screen and (max-width: 380px) {
  .col-xxs-12 {
    width: 100%;
  }
  .col-xxs-12 img {
    width: 100%;
  }
}

a.bsp-controls, a.bsp-controls:visited, a.bsp-controls:active{
 position:relative;
}

.bsp-controls.next{
    float:right;
    margin-right:50px;
    color:blue;
}

.bsp-controls.previous{
    float:left;
    margin-left:50px;
    color:blue;
}
&#13;
**Html page**


<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>Bootstrap Photo Gallery Demo</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
  <link href="jquery.bsPhotoGallery.css" rel="stylesheet">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="jquery.bsPhotoGallery.js"></script>

  <script>
    $(document).ready(function() {
      $('ul.first').bsPhotoGallery({
        "classes": "col-lg-2 col-md-4 col-sm-3 col-xs-4 col-xxs-12",
        "hasModal": true,
        // "fullHeight" : false
      });
    });
  </script>
</head>
<style>
  @import url(https://fonts.googleapis.com/css?family=Bree+Serif);
  body {
    background: #ebebeb;
  }
  
  ul {
    padding: 0 0 0 0;
    margin: 0 0 40px 0;
  }
  
  ul li {
    list-style: none;
    margin-bottom: 10px;
  }
  
  .text {
    /*font-family: 'Bree Serif';*/
    color: #666;
    font-size: 11px;
    margin-bottom: 10px;
    padding: 12px;
    background: #fff;
  }
</style>

<body>
  <div class="container">
    <div class="row" style="text-align: center; border-bottom: 1px dashed #ccc; padding: 0 0 20px 0; margin-bottom: 40px;">
      <h3 style="font-family: 'Bree Serif', arial; font-weight: bold; font-size: 30px;">
        <a style="text-decoration: none; color: #666;" href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Bootstrap
        					Photo Gallery jQuery plugin <span style="color: red;">Demo</span>
        				</a>
      </h3>
      <p>
        Resize your browser and watch the gallery adapt to the view port size. Clicking on an image will activate the Modal. Click <strong><a
        					style="color: red"
        					href="http://michaelsoriano.com/create-a-responsive-photo-gallery-with-bootstrap-framework/">Here</a></strong> to go back to the tutorial
      </p>
    </div>

    <ul class="row first">

      <li><img alt="Rocking the night away" src="http://demo.michaelsoriano.com/images/photodune-3552322-insurance-xs.jpg"></li>

      <li>
        <img alt="Food Explosion" src="http://demo.michaelsoriano.com/images/photodune-3807845-food-s.jpg">
        <div class="text">Eiusmod tempor enim ad minim veniam</div>
      </li>
      <li>
        <img alt="Office worker sad" src="http://demo.michaelsoriano.com/images/photodune-3835655-down-office-worker-xs.jpg">
        <div class="text">Ut enim ad minim veniam</div>
      </li>

      <li>
        <img alt="" src="http://demo.michaelsoriano.com/images/photodune-4619216-ui-control-knob-regulators-xs.jpg">
        <div class="text">Do eiusmod tempor</div>
      </li>



    </ul>
  </div>
  <!-- /container -->

  <body>

</html>
&#13;
&#13;
&#13;