为什么这个jQuery脚本不把HTML页面上的视频声明替换为GIF声明?
Why isn't this jQuery script replacing the video declaration with the GIF declaration on an HTML page
我正在编写一个jQuery脚本来检测访问我的网站的用户是在iOS设备上,当他们是,将网站的背景从视频切换到GIF,因为。mp4和。webm文件不支持iOS版本的Safari。该脚本使用modernizr.js和uissearch .js作为支持文件。该脚本直接包含在HTML中,而不是作为单独的文件。
$(document).ready(function() {
if((navigator.userAgent.match(/iPhone/i)) ||
(navigator.userAgent.match(/iPod/i)) ||
(navigator.userAgent.match(/iPad/i))) {
('.video-background').remove();
('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
}
});
它试图改变的HTML看起来像这样:
<body div="main" class="html front not-logged-in no-sidebars page-node page-node- page-node-16 node-type-panel role-1 lightbox-processed">
<div class="video-background">
<video id="video" preload="none" poster="./index_files" autoplay="autoplay" loop="true">
<source src="./index_files/Test_cut_soundless_WEBM.webm" type="video/webm">
<source src="./index_files/Test_cut_soundless_MP4.mp4" type="video/mp4">
</video>
</div>
它试图将其更改为:
<body div="main" class="html front not-logged-in no-sidebars page-node page-node- page-node-16 node-type-panel role-1 lightbox-processed">
<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">
我是一个非常初级的程序员,如果有人能告诉我这里不工作的地方,那将非常感激!
在调用remove和preend时,您在开始处丢失了$
:
('.video-background').remove();
('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
替换为:
$('.video-background').remove();
$('body').prepend('<img src="./index_files/Test_cut_GIF.gif" id="backgroundimage" class="video-background">');
我希望这对你有帮助。
相关文章:
- 获取HTML属性中CSS声明的值
- 如何检查用户在html5视频播放器中观看了完整的视频
- 如何使用php文件中的GET来获取我在.js文件中声明的变量
- 在javascript中添加和显示对象的随机数组中的视频
- 如何解析Brightcove视频中的视频缩略图
- 如何创建包含多个视频的视频横幅
- 如何使用angularjs在iframe中嵌入来自数据库的视频链接
- 使我的视频标头响应
- 调用函数中声明的变量
- 使用在函数外部声明的变量的 Javascript 返回值 + undefined
- Javascript的视频音量问题
- 我可以设置HTML5文件上传的视频长度限制吗
- 如何获得一个与用“”声明的变量工作方式相同的变量;设“;或在with块中
- 如何将缩略图链接到新页面上的视频
- 使用SeleniumWebdriver(带有Java)测试没有ID的视频
- 是否可以在另一个变量中使用未声明的变量
- AudioContext从blob获取数据的视频创建MediaElementSource
- 如何让iPhone用户在我的网站上观看带字幕的视频
- 如何修改此功能以获得最受欢迎的视频?(YouTube API v3)
- 为什么这个jQuery脚本不把HTML页面上的视频声明替换为GIF声明?