Frontend

jQuery Responsive frame video

20 Tháng 10, 2018 admin 1 min read

[javascript]
(function (root, factory) {
if (typeof define === ‘function’ && define.amd) {
define(‘jquery.responsiveiframes’, [‘jquery’], factory);
} else if (typeof exports === ‘object’) {
module.exports = factory(require(‘jquery’));
} else {
/*root.responsiveiframes = */factory(root.jQuery);
}
}(this, function ($) {
‘use strict’;

$(window).on(‘resize load’, function() {

$(‘iframe,embed’).not(‘.no-aspect-ratio’).each(function() {

var $el = $(this);
var aspectRatio = $el.data(‘aspect-ratio’), maxWidth = $el.data(‘max-width’);

if (aspectRatio == null) {

maxWidth = parseFloat($el.css(‘width’))
? $el.width()
: Infinity;

aspectRatio = $el.height() / $el.width();

$el.data({ ‘aspect-ratio’: aspectRatio, ‘max-width’: maxWidth })
.removeAttr(‘height’)
.removeAttr(‘width’)
.css({ ‘width’: ”, ‘height’: ” });
}
var width = Math.min(maxWidth, $el.parent().width());
$el
.width(width)
.height(width * $el.data(‘aspect-ratio’));
});
});
}));
[/javascript]

0 0 đánh giá
Đánh giá bài viết
Please wait...
Theo dõi
Thông báo của
0 Góp ý
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất