javascript - HTML、CSS、JS 未运行

标签 javascript html css

我是 html、css 和 js 的新手,一直在关注 codecademy。我刚刚第一次创建我的文件并尝试遵循此 https://jsfiddle.net/svArtist/9ewogtwL/尝试获取带有播放/暂停叠加层的视频的示例。我无法使用下面的代码播放视频,不确定我做错了什么或遗漏了什么。这正是我的代码在每个文件中的写法。我的猜测是我的 html 或 js 写得不正确?

index.html

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    <script type="text/javascript" src="scripts.js"></script>
</head>

<body>
    <div class="wrapper">
        <video class="video">
            <source src="http://e14aaeb709f7cde1ae68-a1d0a134a31b545b257b15f8a8ba5726.r70.cf3.rackcdn.com/projects/31432/1427815464209-bf74131a7528d0ea5ce8c0710f530bb5/1280x720.mp4" type="video/mp4" />
        </video>
        <div class="playpause"></div> 
   </div>

</body>
</html>

脚本.js

$('.video').parent().click(function () {
if($(this).children(".video").get(0).paused){
    $(this).children(".video").get(0).play();
    $(this).children(".playpause").fadeOut();
}else{
   $(this).children(".video").get(0).pause();
    $(this).children(".playpause").fadeIn();
}
});

mystyle.css

.video {
width: 100%;
border: 1px solid black;
}
.wrapper{
display:table;
width:auto;
position:relative;
width:50%;
}
.playpause {
background-image:url(http://png-4.findicons.com/files/icons/2315/default_icon/256/media_play_pause_resume.png);
background-repeat:no-repeat;
width:50%;
height:50%;
position:absolute;
left:0%;
right:0%;
top:0%;
bottom:0%;
margin:auto;
background-size:contain;
background-position: center;
}

最佳答案

您的 script.js 包含 JQuery 代码而不是 vanilla JS。 您需要链接到代码运行所需的 JQuery 库。

尝试将 CDN 源添加到您的 head 标签中

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

请参阅下面的链接以供引用。

https://www.w3schools.com/jquery/jquery_get_started.asp

关于javascript - HTML、CSS、JS 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50538142/

相关文章:

javascript - 分割字符串,评估各部分并重新连接

html - CSS: Div的位置

php - Foundation- Contact Form 调整

javascript - 使用 JQuery 倒数百分比

javascript - 如何将数组值从 javascript 传递到 angularjs Controller

javascript - 如何解决 Aspx.cs 中文本框的问题

javascript - Angular 2 组件自定义属性在构造函数中为 null

html - 我想对特定的 h1 标签进行特定的编辑

css - 如何在传单图层控件中更改背景样式(css)

html - 无法让 <span> 背景工作