Javascript on Oxygen Builder



我在wordpress的oxygen Builder中遇到JS问题。我试图集成一个视频,我找到了一个JS脚本来调整它的大小(使其响应(。

视频来源:.webm

// Find all YouTube videos
// Expand that selector for Vimeo and whatever else
var $allVideos = $("video[src^='//site-web.fr']"),
// The element that is fluid width
$fluidEl = $("body");
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
$(this)
.data('aspectRatio', this.height / this.width)
// and remove the hard coded width/height
.removeAttr('height')
.removeAttr('width');
});
// When the window is resized
$(window).resize(function() {
var newWidth = $fluidEl.width();
// Resize all videos according to their own aspect ratio
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.data('aspectRatio'));
});
// Kick off one resize to fix all videos on page load
}).resize();

我收到以下错误消息:TypeError:$不是函数。(在第3行的'$("video[src^='//site-web.fr']"中,'$'未定义(。

我得到了答案,在Oxygen builder中,您必须使用jQuery而不是$进行调用。因此:

// Find all YouTube videos
// Expand that selector for Vimeo and whatever else
var $allVideos = jQuery("video[src^='//clef-energies.fr']"),
// The element that is fluid width
$fluidEl = jQuery("body");
// Figure out and save aspect ratio for each video
$allVideos.each(function() {
jQuery(this)
.data('aspectRatio', this.height / this.width)
// and remove the hard coded width/height
.removeAttr('height')
.removeAttr('width');
});
// When the window is resized
jQuery(window).resize(function() {
var newWidth = $fluidEl.width();
// Resize all videos according to their own aspect ratio
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.data('aspectRatio'));
});
// Kick off one resize to fix all videos on page load
}).resize();

最新更新