- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将此脚本粘贴到我的 meteor 应用程序中,但我不知道如何稍微更改格式以使其适合我的“Template.page.events”,有人可以帮忙吗?
我是初学者,遇到困难
(function(){
var v = document.querySelector('video'),
n = document.querySelector('source').src.replace(/.*\/|\..*$/g,''),
c = document.querySelector('canvas'),
save = document.querySelector('#save ul'),
ctx = c.getContext('2d');
v.addEventListener('loadedmetadata',function(ev){
var ratio = v.videoWidth/v.videoHeight,
w = 400,
h = parseInt(w / ratio, 10),
time = 0,
img = null,
li = null;
c.width = w;
c.height = h + 40;
v.addEventListener('timeupdate',function(ev){
if(v.paused){
ctx.fillStyle = 'rgb(0, 0, 0)';
ctx.fillRect(0, 0, w, h);
ctx.drawImage(v, 0, 40, w, h);
ctx.font = '20px Calibri';
ctx.fillStyle = 'lime';
ctx.fillText(n, 5, 20);
time = format(v.currentTime);
ctx.fillStyle = 'white';
ctx.fillText(time, 395 - ctx.measureText(time).width, 20);
}
},false);
c.addEventListener('click',function(ev){
li = document.createElement('li');
img = document.createElement('img');
li.appendChild(img);
save.appendChild(li);
img.src = ctx.canvas.toDataURL('image/png');
},false);
},false);
function format(time){
var hours = parseInt((time / 60 / 60) % 60, 10),
mins = parseInt((time / 60) % 60, 10),
secs = parseInt(time, 10) % 60,
hourss = (hours < 10 ? '0' : '') + parseInt(hours, 10) + ':',
minss = (mins < 10 ? '0' : '') + parseInt(mins, 10) + ':',
secss = (secs < 10 ? '0' : '') +(secs % 60),
timestring = ( hourss !== '00:' ? hourss : '' ) + minss + secss;
return timestring;
};
})();
最佳答案
假设我们有这个 Meteor 模板标记:
<template name="page">
<video controls autoplay>
<source src="/videos/video.mp4">
</video>
<canvas></canvas>
<ul>
{{#each screenshots}}
{{> screenshot}}
{{/each}}
</ul>
</template>
<template name="screenshot">
<li>
<img src="{{source}}">
</li>
</template>
我添加了一个子模板来处理以 Meteor 方式完成的屏幕截图列表生成:无需直接操作 DOM 来插入 HTML 元素。
首先我们需要创建一个 reactive-var
来将截图列表源保存为一个数组:
Template.page.onCreated(function(){
this.screenshots = new ReactiveVar([]);
});
Template.page.helpers({
screenshots:function(){
return Template.instance().screenshots.get();
}
});
不要忘记meteor add reactive-var
。
我们可以将对 onRendered
模板生命周期事件中的 video
和 canvas
元素的引用保存为模板属性:
Template.page.onRendered(function(){
this.video = this.find("video");
this.canvas = this.find("canvas");
});
然后我们必须使用 Meteor 事件映射重写标准的 HTML 事件处理,这非常简单,只需使用语法 "event selector"
。
Template.page.events({
"loadedmetadata video":function(event,template){
var ratio = template.video.videoWidth / template.video.videoHeight;
var canvasWidth = 400;
var canvasHeight = parseInt(canvasWidth / ratio, 10);
template.canvas.width = w;
template.canvas.height = h + 40;
},
"timeupdate video":function(event,template){
function format(time){
var hours = parseInt((time / 60 / 60) % 60, 10);
var mins = parseInt((time / 60) % 60, 10);
var secs = parseInt(time, 10) % 60;
var hourss = (hours < 10 ? '0' : '') + parseInt(hours, 10) + ':';
var minss = (mins < 10 ? '0' : '') + parseInt(mins, 10) + ':';
var secss = (secs < 10 ? '0' : '') +(secs % 60);
var timestring = ( hourss !== '00:' ? hourss : '' ) + minss + secss;
return timestring;
}
//
if(template.video.paused){
var ctx = template.canvas.getContext("2d");
ctx.fillStyle = "rgb(0, 0, 0)";
ctx.fillRect(0, 0, template.canvas.width, template.canvas.height);
ctx.drawImage(template.video, 0, 40, template.canvas.width, template.canvas.height);
ctx.font = "20px Calibri";
ctx.fillStyle = "lime";
ctx.fillText("caption", 5, 20);
var time = format(template.video.currentTime);
ctx.fillStyle = "white";
ctx.fillText(time, 395 - ctx.measureText(time).width, 20);
}
},
"click canvas":function(event,template){
var screenshots = template.screenshots.get();
screenshots.push({
source: template.canvas.toDataURL("image/png")
});
template.screenshots.set(screenshots);
}
});
关于javascript - 需要更改 JS 事件格式以适应 Jquery 和 Meteor (Template.mysite.events) 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30308448/
我遇到了问题,似乎无法解决。 基本上,我希望我的菜单和文本随着分辨率的变化/放大/缩小而调整大小;图片工作正常,内容 div 工作正常,只是菜单似乎无法适应。 请帮我解决这个问题.. 普通 View
我在map reduce上开发了大约20个工作,包括pagerank算法。我从未发现任何具有挑战性的问题可以在线适应mapreduce框架。我想提高自己的技能。有这样的指南吗? 最佳答案 您正在寻找的
我了解到 Java 中没有 NOR,我可以使用 !A && !B 或 !(A||B)。既然 A 和 B 都是假的,为什么我不能使用 !A || B? 最佳答案 因为Java没有NOR运算符,你的表达式
我需要根据构建 CLI 工具的要求评估“GO”,该工具应该可以在不同的操作系统中运行。这是如何在诸如“Cloud Foundry CLI”之类的 CLI 工具中实现的?GO 如何处理这种对操作系统的适
所以我试图让我的下拉菜单正常工作。下拉列表位于我的标题中的列表项下,该列表项会根据用户的用户名而变化。这使得大小不同,但我无法让下拉菜单跟随宽度调整大小。 示例 1: http://jsfiddle.
我已经很努力了,但我还是被 matplotlib 卡住了。请忽略,mpl 文档让我有点困惑。我的问题涉及以下方面: 我用 matshow 函数画了一个对称的 n*n 矩阵 D。行得通。 我想做同样的事
我正在尝试调整 Boyer-Moore c(++) Wikipedia implementation获取字符串中模式的所有匹配项。实际上,维基百科实现返回第一个匹配项。主要代码如下: char* bo
我在底部嵌套了带有文本的 flex 元素。顶部元素具有小于文本的固定宽度: .list-header { display: flex; width: 150px; height: 80px
我想初始化 std::any带有仅 move 类型变量。我找到了 Cannot move std::any . 编译错误案例 在使用链接答案中的 shared_ptr 解决方法之前,我测试了以下代码:
现在我正在使用 webview 处理 ListView 。在这个 listview webview 中用于显示图像。它来自 url。现在我面临一个问题,我无法从 url 获得唯一尺寸的图像,一些图像很
我的文件夹结构是这样的: src --main.cpp tests --src ----main_test.cpp Makefile 我想制作一个像make main_test这样的目标,以便能够以.
前段时间我也在讨论类似的话题。我正在查看我的应用程序,我认为它有很多不必要的代码。我的意思是我有服务负责从两家书店的不同类别的书籍中抓取数据。现在我有 5 个类别,所以我有 5 个方法,但如果我要添加
我使用多个 div 子元素创建父元素,然后根据 data-value 属性在 JavaScript 中计算这些子元素的宽度。 如果我对所有 child 的计算宽度求和,我最终将得到 100%。但出于某
我像这样使用减速板 gem : require 'airbrake' Airbrake.configure do |config| config.api_key = 'XXXXX' confi
我们在企业环境中有一个 svn 存储库结构,如下所示: root libs shared_lib1 shared_lib2 private_lib public_cod
我制作了一个应用程序,其中有许多从 UIView 子类化的 View 。这些 View 的大小和方向是随机的,并且可以保存应用程序屏幕的状态。当用户在打开屏幕的同一设备上保存屏幕时,屏幕状态为“正常”
我需要调整 lucene 的 StandardTokenizer 以适应有关 twitter 数据的一些特殊目的。目前,我使用 StandardTokenizer 来标记一些我想要处理的推文。它工作得
在Windows Store应用中,如果内容是固定的,我们可以把它封装成一个ViewBox,让内容适应不同的分辨率。但是,如果内容不固定,在我的应用程序中,有一个 GridView 哪些项目是动态的,
一切都在标题中。 在我的应用程序中,根据用户所做的选择,我用一个列表填充一个组合框,该列表有时很小(1 个元素)有时很大(150 个元素)。 我想要的不是在启动时将固定高度设置为给定值,而是将 max
我的 2 div 动画感谢我下面的 jquery 脚本。当屏幕小于 700px 时,div 变成更小的正方形(35px 而不是 50px)。我希望 .animate({width:100px}); 仅
我是一名优秀的程序员,十分优秀!