Bootstrap snippets and tips
Mar 6, 2016 · 2 分钟阅读

Update popover text:

$('[data-toggle="popover"]').popover({
  html: true,
  trigger: 'focus',
  content: '',
  placement: 'bottom'
});

$('[data-toggle="popover"]').data('bs.popover').options.content = 'new content';
$('[data-toggle="popover"]').popover('show');

to dismiss the popover on iOS, you may use body { cursor: pointer; }

Specific markup required for dismiss-on-next-click For proper cross-browser and cross-platform behavior, you must use the <a> tag, not the <button> tag, and you also must include the role="button” and tabindex attributes.

Center modal dialog with CSS:

.center-container.modal { padding: 0!important; text-align: center;}
.center-container.modal:before { content: ''; display: inline-block; margin-right: -4px; height: 100%; vertical-align: middle;}
.center-container.modal .modal-dialog { display: inline-block; text-align: left; vertical-align: middle;}

Vertically center modal dialog with JS:

function reposition() {
  var modal = $(this);
  var dialog = modal.find('.modal-dialog');

  modal.css('display', 'block');
  dialog.css('margin-top', Math.max(0, ($(window).height() - dialog.height()) / 2));
}

$('.modal').on('show.bs.modal', reposition);

$(window).on('resize', function() {
  $('.modal:visible').each(reposition);
});
.modal.fade .modal-dialog { transform: translate3d(0, 100vh, 0);}
.modal.in .modal-dialog { transform: translate3d(0, 0, 0);}
.modal .modal-dialog { position: absolute; left: 0; right: 0; bottom: 0;}

Set modal dialog's max height:

function setModalMaxHeight(element) {
  var $element = $(element);
  var $content = $element.find('.modal-content');
  var borderWidth = $content.outerHeight() - $content.innerHeight();
  var dialogMargin = $(window).width() < 768 ? 20 : 60;
  var contentHeight = $(window).height() - (dialogMargin + borderWidth);
  var headerHeight = $element.find('.modal-header').outerHeight() || 0;
  var footerHeight = $element.find('.modal-footer').outerHeight() || 0;
  var maxHeight = contentHeight - (headerHeight + footerHeight);

  $content.css({
    'overflow': 'hidden'
  });

  $element
    .find('.modal-body').css({
      'max-height': maxHeight,
      'overflow-y': 'auto'
    });
}

$('.modal').on('show.bs.modal', function() {
  $(this).show();
  setModalMaxHeight(this);
});

$(window).resize(function() {
  if ($('.modal.in').length !== 0) {
    setModalMaxHeight($('.modal.in'));
  }
});

Keep popover open while it being hovered

var originalLeave = $.fn.popover.Constructor.prototype.leave;
$.fn.popover.Constructor.prototype.leave = function(obj) {
  var self = obj instanceof this.constructor ?
    obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type);
  var container, timeout;

  originalLeave.call(this, obj);

  if (obj.currentTarget) {
    container = $(obj.currentTarget).siblings('.popover');
    timeout = self.timeout;
    container.one('mouseenter', function() {
      clearTimeout(timeout);
      container.one('mouseleave', function() {
        $.fn.popover.Constructor.prototype.leave.call(self, self);
      });
    });
  }
};
$('[data-toggle=popover]').popover({
  trigger: 'hover',
  delay: { show: 50, hide: 400 }
});
← Previous Post Next Post →

Ryun的博客
与其感慨路难行,不如马上出发。

atom css design git html javascript jekyll laravel life mac mobile optimization sublime tool vscode vue
mac

About

你好,❤朋友

这里是 Ryun 的博客 📝

📝记录了我学习 🔎的过程

作为一名前端攻城狮 🦁

希望能和大家一起 🔎

共同进步 🏃

🦁的特长:

  • HTML5
  • CSS3
  • JavaScript
  • Vue.js
  • 微信小程序
  • 熟练配合 Node.js、PHP 和 Laravel
  • 熟练使用各种开发和设计工具

🦁喜欢 🆒🆒的东西

对提升效率和美感的事物有兴趣 😋

欢迎 👏交流


see this hugo-theme-dream-ink