小编Mau*_*lar的帖子

无需重复的javascript组合

给定

[
  ["blue", "red"],
  [1, 2],
  [true, false],
]
Run Code Online (Sandbox Code Playgroud)

如何在javascript中获得可能的组合?:

blue, 1, true
blue, 1, false
blue, 2, true
blue, 2, false
red, 1, true
red, 1, false
red, 2, true
red, 2, false
Run Code Online (Sandbox Code Playgroud)

顺序无关紧要。

javascript combinations permutation

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

如何在Angular 2中执行无限动画?

基本上,我想在角度(当前为4)中使用web-animations-api polyfill来对元素执行无限动画.

让我们看一个基本的非角度示例:

var ball = document.getElementById('ball');

ball.animate([
  { transform: 'scale(0.5)' },
  { transform: 'scale(1)' }
], {
  duration: 1000,
  iterations: Infinity,
  direction: 'alternate',
  easing: 'ease-in-out'
});
Run Code Online (Sandbox Code Playgroud)
.container {
  position: relative;
  width: 100%;
  height: 200px;
}

.ball {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 2px solid #E57373;
  background: #F06292;
  box-shadow: 0px 0px 15px #F06292;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/web-animations/2.2.5/web-animations.min.js"></script>
<div class="container">
  <div class="ball" id="ball"><div>
</div>
Run Code Online (Sandbox Code Playgroud)

我如何将其翻译成Angular?

这是我到目前为止尝试过但只运行一次:

animations: [ …
Run Code Online (Sandbox Code Playgroud)

javascript web-animations angular angular-animations

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

aria-labelledby 不适用于 NVDA/Firefox

我需要一些帮助才能使 NVDA 屏幕阅读器读取我在 index.html 中编写的数学表达式的自定义描述。数学表达式位于句子内。所以它看起来很像这样:

<div>
  some text here...
  &epsilon;<sub>x</sub> = -200(10<sup>-6</sup>), 
  &epsilon;<sub>y</sub> = 550(10<sup>-6</sup>), 
  &gamma;<sub>xy</sub> = 150(10<sup>-6</sup>)
  some more text here...
<div>
Run Code Online (Sandbox Code Playgroud)

问题是屏幕阅读器无法读取上标或减号。

为了解决这个问题,我添加了aria-labelledby一个自定义描述:

<label id="label">Formula description here</label>
<div>
  some text here...
  <span aria-labelledby="label">
    &epsilon;<sub>x</sub> = -200(10<sup>-6</sup>), 
    ...
  </span>
<div>
Run Code Online (Sandbox Code Playgroud)

它部分解决了问题(仅限 Voice Over/MacOS)。但 Windows/NVDA/Firefox 不起作用。它只是忽略它。

我尝试过使用aria-labelandaria-describedby但似乎不起作用。提前致谢。

html accessibility wai-aria nvda

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

如何将 html 元素放在 Fabric.js 元素上

我想在fabric.Group 内部的fabric.js 元素上放置一个按钮。

如何获取相对于织物元素的画布容器的左上角坐标,然后将其设置到按钮?

jsfiddle: https: //jsfiddle.net/d9sp16yc/2/

我尝试过这样这样的事情,但没有得到我想要的结果。按钮稍微向右或向左/底部或顶部移动。

另一件事是,setSize当窗口大小调整时,该函数会缩放组(只是为了获得响应行为):

function setSize() {
  var width = $('.container').width();
  var height = width * 0.6;
  canvas.setWidth(width);
  canvas.setHeight(height);
  group.scaleToWidth(width);
  canvas.centerObjectH(group);
  // setPos($('#btn'), rect);
}
Run Code Online (Sandbox Code Playgroud)

问题是这会影响坐标的计算方式。

即使窗口大小调整后,是否可以将其放在织物对象的左上角?

我真的需要一个快速的解决方案,所以我将不胜感激任何建议/帮助来实现这一目标。

提前致谢。

javascript canvas fabricjs

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