首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >某些元素的角度设置计时器

某些元素的角度设置计时器
EN

Stack Overflow用户
提问于 2019-04-07 10:33:41
回答 1查看 93关注 0票数 0

这里我有一些jspdf函数

代码语言:javascript
复制
  public captureScreen() {
    // Start from here 
    this.loading = true;

    const data = document.getElementById('convert');
      html2canvas(data).then(canvas => {
      const imgWidth = 208;
      const pageHeight = 295;
      const imgHeight = canvas.height * imgWidth / canvas.width;
      const heightLeft = imgHeight;
      const contentDataURL = canvas.toDataURL('image/png');
      const pdf = new jspdf('p', 'mm', 'a4');
      const position = 0;
      pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
      pdf.save('Test.pdf');
      // Until here
      this.loading = false;
    });
  }

我想让这个函数运行一秒钟,直到它再次将this.loading返回为false。我怎样才能让一个计时器在执行最后一段代码之前设置2-3秒?

EN

回答 1

Stack Overflow用户

发布于 2019-04-07 11:29:27

使用set timeout函数延迟几秒钟

代码语言:javascript
复制
// When calling function
this.loading = true;
setTimeout(function() { captureScreen(); }, 3000);

public captureScreen() {
    const data = document.getElementById('convert');
      html2canvas(data).then(canvas => {
      const imgWidth = 208;
      const pageHeight = 295;
      const imgHeight = canvas.height * imgWidth / canvas.width;
      const heightLeft = imgHeight;
      const contentDataURL = canvas.toDataURL('image/png');
      const pdf = new jspdf('p', 'mm', 'a4');
      const position = 0;
      pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
      pdf.save('Test.pdf');
      // Until here
      this.loading = false;
    });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55555118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档