本文介绍了如何调整Twitter的Bootstrap 2模式窗口的大小并为其设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问问是否有人可以给我一些想法来动态调整bootrap 2模态窗口的大小,并具有流畅的动画效果.

I would like to ask if anybody can give me some ideas to dynamically resize a bootrap 2 modal window, with animated effect smoothly.

我正在考虑使模态的内容更改时,它像colorbox一样工作,它会根据内容的尺寸更改其宽度和高度.

I am thinking of making it work like colorbox when the content of the modal changes it changes its width and height depending on the contents dimensions.

推荐答案

什么会触发调整大小?在这里查看: https://stackoverflow.com/a/245011/1596547 您可以使用它来调整模式的大小.请参阅: http://bootply.com/71672

What should trigger the resize?Look here: https://stackoverflow.com/a/245011/1596547 You can use this to resize your modal.See: http://bootply.com/71672

有关Twitter的Bootstrap 3,请参阅: https://stackoverflow.com/a/18042644/1596547

For Twitter's Bootstrap 3, see: https://stackoverflow.com/a/18042644/1596547

html :

<div class="container">
<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
    <h3 id="myModalLabel">Modal header</h3>
      </div>
  <div class="modal-body">
      <!--long text--><a href="#" id="resize">Resize</a>
 </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

</div>

javascript :

$('#resize').click(function(){$("#myModal").animate({width:"200px"},600,'linear');});

保持模态的位置居中:

中心位置由.modal类的负左边界设置.负的左边距的值将为模态宽度的一半.因此,在调整大小时要保持位置居中,请尝试以下操作:

The centered position is set by a negative left-margin of the .modal class. The value of this negative left-margin will be half the width of the modal. So to keep the position centered when resizing try something like:

    $("#myModal").animate({"width":"200px","margin-left":"-100px"},600,'linear');

轻松:

jQuery核心附带两种缓动:线性(在整个动画中以恒定的速度进行进度)和摆动(jQuery核心的默认缓动),在动画的开始和结束时的进度比在动画的中间稍微慢一些.动画.

jQuery core ships with two easings: linear, which progresses at a constant pace throughout the animation, and swing (jQuery core's default easing), which progresses slightly slower at the beginning and end of the animation than it does in the middle of the animation.

jQuery UI提供了一些其他的缓动功能,请参见: http://api.jqueryui.com/easings/

jQuery UI provides several additional easing functions see: http://api.jqueryui.com/easings/

或此插件: http://gsgd.co.uk/sandbox/jquery/easing/另请参见: http://easings.net/

Or this plugin: http://gsgd.co.uk/sandbox/jquery/easing/ see also: http://easings.net/

这篇关于如何调整Twitter的Bootstrap 2模式窗口的大小并为其设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:25