Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jQuery中添加媒体属性_Javascript_Jquery_Video_Html5 Video - Fatal编程技术网

Javascript 如何在jQuery中添加媒体属性

Javascript 如何在jQuery中添加媒体属性,javascript,jquery,video,html5-video,Javascript,Jquery,Video,Html5 Video,我使用的是一个HTML5和jQuery交互式视频库,其中包含一个从教程改编的Flash回退功能。场地是流动的。我不知道jQuery,我正在尝试让小型移动设备播放比当前服务(800x450)更小尺寸(480x272)的视频 下面是我如何修改代码的,但媒体查询无法识别。我的格式错误是什么 var videoCode = '<video width="'+480+'" height="'+272+'" controls autoplay autobuffer>

我使用的是一个HTML5和jQuery交互式视频库,其中包含一个从教程改编的Flash回退功能。场地是流动的。我不知道jQuery,我正在尝试让小型移动设备播放比当前服务(800x450)更小尺寸(480x272)的视频

下面是我如何修改代码的,但媒体查询无法识别。我的格式错误是什么

var videoCode = '<video width="'+480+'" height="'+272+'" controls autoplay autobuffer>
                 <source src="video/'+videoFile+'_small.ogv" type="video/ogg" media="screen and (max-width:500px)">
                 <source src="video/'+videoFile+'_small.mp4" type="video/mp4" media="screen and (max-width:500px)">
                 <video width="'+800+'" height="'+450+'" controls autoplay autobuffer>
                 <source src="video/'+videoFile+'.ogv" type="video/ogg" />
                 <source src="video/'+videoFile+'.mp4" type="video/mp4" />
var-videoCode=”

编辑:修复了编码布局

您的代码似乎缺失,但要添加/更新元素的属性是
$('someselector')。attr('attrname','value')

//var videoFile=$(this.attr('videoFile');
var videoFile=(screen.width<500)$(this.attr('videofile')+“_small”:$(this.attr('videofile');
var videoPoster=$(this.attr('videofile');
var videoPoster=$(this.attr('videofile');
var videoWidth=(屏幕宽度<500)?200 : 800;
变量videoHeight=(屏幕高度<500)?200 : 450;

事实证明,这就是解决办法

var videoCode='这是它前面的部分,如果你是这个意思的话:var videoFile=$(This.attr('videoFile');var videoPoster=$(this.attr('videofile');var videoWidth=Number($(this).attr('videoWidth');var videoHeight=Number($(this.attr('videoHeight'));谢谢现在,jQuery不是使用attr()方法的高级Attirbtes吗?我已经学习了jQuery,现在意识到需要使用“if…else”语句,而不是变量定义中的媒体查询。下面是变量定义末尾的当前语句:$('#videoPlayer').html(videoCode);请原谅术语上的错误!谢谢
//var videoFile = $(this).attr('videofile');
    var videoFile = (screen.width < 500) ? $(this).attr('videofile') + "_small" : $(this).attr('videofile');
    var videoPoster = $(this).attr('videofile');
    var videoPoster = $(this).attr('videofile');
    var videoWidth = (screen.width < 500) ? 200 : 800;
    var videoHeight = (screen.height < 500) ? 200 : 450;