小编for*_*sto的帖子

backbone.js清空一个集合

我需要清空一个集合,按顺序删除每个项目.

this.nodes.each(function(node){
  this.nodes.remove(node);
}, this);
Run Code Online (Sandbox Code Playgroud)

不起作用,因为在删除每个节点时,它会更改集合的长度.制作一个临时数组,然后迭代它的工作原理.有没有更好的办法?

javascript collections backbone.js

5
推荐指数
1
解决办法
3805
查看次数

Web Audio API——频率调制在 Chrome / Safari 中听起来不同

我正在为 Web Audio API 合成器开发基于浏览器的修补界面。频率调制(将一个振荡器与另一个振荡器的频率挂钩)在 Chrome 中按预期工作。它应该是一种科幻声音,就像频率波动为30Hz的300Hz正弦波。

在 Safari(和 Mobile Safari)中,听起来只是低沉的隆隆声。听起来好像有FM,但基频不对。这是否只是浏览器的一个怪癖,将在未来的版本中得到解决?现在有解决办法吗?

这是视觉/交互版本:
html5 调频合成器
http://forresto.github.com/dataflow-webaudio/

还有fiddle版本,用最少的代码演示效果:
http ://jsfiddle.net/FVaWL/28/

var mod, modGain, osc;

var out = context.destination;

var startTest = function(){
    mod = context.createOscillator();
    mod.frequency.value = 8;

    modGain = context.createGain();
    modGain.gain.value = 30;

    osc = context.createOscillator();
    osc.frequency.value = 300;

    mod.connect(modGain);
    modGain.connect(osc.frequency);
    osc.connect(out);

    osc.start(0);
    mod.start(0);
};

var stopTest = function(){
    osc.stop(0);
    mod.stop(0);
    mod = modGain = osc = null;
};
Run Code Online (Sandbox Code Playgroud)

javascript web-audio-api

5
推荐指数
1
解决办法
3040
查看次数

在Polymer shadow DOM元素中切换主题

我们正在制作一个相当复杂的应用程序,它将具有不同的CSS文件集以应用于各种自定义元素.动态切换包含的样式表有什么好方法?

<template>
  <link rel="stylesheet" href="../themes/dark.css">
  <div id="container"></div>
</template>
Run Code Online (Sandbox Code Playgroud)

<template>
  <link rel="stylesheet" href="../themes/light.css">
  <div id="container"></div>
</template>
Run Code Online (Sandbox Code Playgroud)

polymer

4
推荐指数
1
解决办法
1858
查看次数

标签之间的 Safari 14.1 localStorage 不同步

这是一个适用于 Safari 14.0(和 Chrome、Firefox)但不适用于 Safari 14.1 的最小案例:https : //ffvix.csb.app

  1. 在 2 个选项卡中打开演示
  2. 输入一些文字,然后按“提交”
  3. 切换到其他选项卡并按“获取”

应该可以通过 localStorage 在同一域上托管的 2 个选项卡之间同步消息。

演示代码:

    <h1>To localStorage</h1>
    <form id="form">
      <input id="text" type="text" />
      <input type="submit" />
    </form>

    <h1>From localStorage</h1>
    <button id="getout">get</button>
    <p id="out"></p>

    <script type="text/javascript">
      const form = document.getElementById("form");
      const text = document.getElementById("text");
      const out = document.getElementById("out");
      const getout = document.getElementById("getout");

      form.addEventListener("submit", function (e) {
        localStorage.setItem("test", text.value);
        e.preventDefault();
      });

      function getIt() {
        out.textContent = localStorage.getItem("test");
      }
      getIt();
      getout.addEventListener("click", getIt);
      window.addEventListener("storage", getIt);
    </script>
Run Code Online (Sandbox Code Playgroud)

javascript safari privacy local-storage

4
推荐指数
1
解决办法
885
查看次数

React.js:批处理setState以确保仅一个DOM布局/绘制

我有一个在做setState的onWheel处理程序,它引起的布局比绘画要多:

车轮布置车轮布置油漆

...通过将事件值更改批处理为一个setState来避免这种情况的任何良好模式?

(我以为这个内置组件有些神奇。)

javascript reactjs

3
推荐指数
1
解决办法
2804
查看次数

NeuQuant.js (JavaScript color quantization) hidden bug in JS conversion

NeuQuant.js works well when the image width and height are a multiple of 100:

300x300 GIF动画 300x300

Otherwise, there is obviously a bug:

299x300 GIF动画 299x300

(These were made with this web app.)

I'm 90% sure that the bug is in NeuQuant.js. I have made tests using it with jsgif and omggif, and both encoders have the same bug. It is only obvious with photographic images (quantize to 256 colors) when the image size is anything other than a multiple of 100. …

javascript quantization neural-network

2
推荐指数
1
解决办法
1215
查看次数