小编Ale*_*tau的帖子

删除"触摸开始"目标后,触摸移动事件不会触发

我正在尝试使用下一个模式实现类似拖动的功能:

  • 订阅marker指针向下事件.
  • 当Down事件触发时,订阅Window Pointer Move和Up事件并删除标记.
  • 移动时执行一些操作.
  • 当Up事件触发取消订阅Move和Up时.

这适用于鼠标事件,但不适用于Touch事件.删除Touch Start目标元素后,它们不会触发.我尝试使用指针事件Polyfill,但它也不起作用.

我正在使用Chrome Dev Tools来模拟触摸事件.看样品:

initTestBlock('mouse', {
  start: 'mousedown',
  move: 'mousemove',
  end: 'mouseup'
});
initTestBlock('touch', {
  start: 'touchstart',
  move: 'touchmove',
  end: 'touchend'
});
initTestBlock('touch-no-remove', {
  start: 'touchstart',
  move: 'touchmove',
  end: 'touchend'
}, true);

function initTestBlock(id, events, noRemove) {
  var block = document.getElementById(id);
  var parent = block.querySelector('.parent');
  var target = block.querySelector('.target');
  target.addEventListener(events.start, function(e) {
    console.log(e.type);
    if (!noRemove) {
      setTimeout(function() {
        // Remove target
        target.parentElement.removeChild(target);
      }, 1000);
    }

    function onMove(e) {
      console.log(e.type);
      var …
Run Code Online (Sandbox Code Playgroud)

javascript events google-chrome touch pointer-events

6
推荐指数
2
解决办法
3060
查看次数

在D3过渡中获得预期的属性值

例如,我有一个过渡:

var sel = container.selectAll('div')
    .transition()
    .duration(1000)
    .attr('transform', 'translate(100,500)');
Run Code Online (Sandbox Code Playgroud)

在某些时刻,我需要知道一些元素落在哪里,例如

setTimeout(() => {
    var value = d3.select('div#target')
        .expectedAttr('transform');
    assertEqual(value, 'translate(100,500)');
}, 500);
Run Code Online (Sandbox Code Playgroud)

D3中有这样的内置功能吗?否则,我将不得不编写自己的包装d3.transition().attr()方法来存储传递给它的值.

编辑

我发现D3 __transition__在元素上创建了字段,它似乎包含有关转换的信息,但我看不到在那里找到目标属性值.

javascript d3.js

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

如何应用 feBlend 并保留源 Alpha

我试图通过在“变亮”和“变暗”模式下应用 feFlood 和 feBlend 来修改图像的颜色。如何保留 Alpha 通道?

<svg>
  <filter id="filter">
    <feFlood result="flood" flood-color="blue" />
    <feBlend in="SourceGraphic" in2="flood" mode="lighten" />
  </filter>
  <image filter="url(#filter)" href="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" />
</svg>
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/utqghr0o/

svg svg-filters

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

如何查明提交是在哪个 Chromium 版本中发布的

例如,我需要知道解决此问题的此提交何时发布,以便能够支持较新和较旧的 Chrome 版本。

google-chrome chromium

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

在写入新内容之前清除文件(Java、Android)

我使用以下代码创建一个新文件(二进制或 JSON)或重写 Android 中的现有文件:

ParcelFileDescriptor pfd = this.getContentResolver().openFileDescriptor(uri, "w");
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
fileOutputStream.write(bytes);
fileOutputStream.close();
pfd.close();
Run Code Online (Sandbox Code Playgroud)

问题是当文件已经存在并且其内容大小较大时,旧内容仍然存在。例如 JSON 可以看起来像

[
    "a",
    "b"
]   "c",
    "d"
]
Run Code Online (Sandbox Code Playgroud)

如何在写入文件之前清理文件,或清除剩余内容?

java android

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