我正在尝试使用下一个模式实现类似拖动的功能:
这适用于鼠标事件,但不适用于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)例如,我有一个过渡:
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__在元素上创建了字段,它似乎包含有关转换的信息,但我看不到在那里找到目标属性值.
我试图通过在“变亮”和“变暗”模式下应用 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)
我使用以下代码创建一个新文件(二进制或 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)
如何在写入文件之前清理文件,或清除剩余内容?
javascript ×2
android ×1
chromium ×1
d3.js ×1
events ×1
java ×1
svg ×1
svg-filters ×1
touch ×1