jquery - 缩放时将视频元素的大小应用于 Bootstrap 模式

标签 jquery twitter-bootstrap twitter-bootstrap-3 bootstrap-modal

我目前正在尝试使用 Bootstrap 来获得一个可以移动的可调整大小的模式。到目前为止,我都可以正常工作,但我遇到了缩放问题。如果我通过单击并拖动缩放图标来缩小模式并仅在一个轴上缩放它,视频就会脱离模式。那么我如何确保模态接收视频元素的当前高度并将其应用到它自己的高度?有没有一种使用 jquery 或 CSS 的简单方法?

https://jsfiddle.net/pdh4cmuf/23/

$('.modal-content').resizable({
    //alsoResize: ".modal-dialog",
    minHeight: 150,
    minWidth: 200
});
$('.modal-dialog').draggable();

$('#myModal').on('show.bs.modal', function () {

    $(this).find('.modal-body').css({
        'max-height':'100%'
    });

});
 $('.modal-backdrop').removeClass("modal-backdrop");    



$(window).load(function () {
            $('#myModal').modal({ backdrop: 'static', keyboard: false});
            $('#myModal').modal('show');
        });

function myFunction() {
            $('#myModal').modal('toggle');
            window.alert('Hello');
        }

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

      </div>
      <div class="modal-body">
       <object class="embed-responsive-item">
<video controls>
    <source src="https://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" type="video/mp4">
    <p>Your browser does not support H.264/MP4.</p>
</video>
</object>
    </div>
  </div>
</div>


.modal {
  pointer-events: none;
  }
.modal-backdrop {
  display: none;
  }

.vertical-alignment-helper {
            display:table;
            height: 100%;
            width: 100%;
            pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
        }
        .vertical-align-center {
            /* To center vertically */
            display: table-cell;
            vertical-align: middle;
            pointer-events:none;
        }
        .modal-content {

            margin: 0 auto;
            pointer-events: all;
            float: left;

            background-color: #ffffff;
        }
        .textarea-nonresizable {
            height: 10em;
            border-radius: 1em;
            resize: none; /* prevents the user-resizing, adjust to taste */
        }
video {
  width: 100%;
  height: auto!important;
}

最佳答案

这是更新后的 fiddle https://jsfiddle.net/pdh4cmuf/26/

**Updated JS**
$('.modal-content').resizable({
    alsoResize: "#video",
    minHeight: 150,
    minWidth: 200
}).bind({
    resizestop: function(event, ui){

        $('video').css({
            'height':ui.size.height - 60,
            'width': ui.size.width - 30
        });
    }
});

-60和-30分别是从计算的高度和宽度中删除的填充。

关于jquery - 缩放时将视频元素的大小应用于 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44981681/

相关文章:

javascript - 当页面从验证中重新加载时,禁用的字段不会被禁用/重置

javascript - 比较多个列表中的属性并删除重复项

javascript - 无法使用 angularjs 和 Bootstrap 日期时间选择器提交表单

html - 非流体容器内的 Bootstrap 流体容器

forms - 如何使用 Twitter 的 Bootstrap 3 以水平形式对齐内联单选框/复选框和帮助 block 元素

javascript - HTML 输入 AJAX 更新 - 使用 Bootstrap 将样式添加到输入字段

javascript - 如何使用 JSON 的一部分填充表

javascript - JQuery 切换和删除 css 类

css - 强制图像为正方形并在 css 中居中

html - 图标的 CSS 位置