Google feedback 的效果 DOM 元素选中是如何实现的?

2017-08-21 18:57:12 +08:00
 safilar

具体见效果图,里面最后那个选择 DOM 的实现

有没有 V 友有过相关的实现思路。

具体链接

https://www.google.com/tools/feedback/reports

2567 次点击
所在节点    JavaScript
4 条回复
autoxbc
2017-08-21 19:40:15 +08:00
gif 看不清,贴图最好贴原始尺寸的
safilar
2017-08-21 20:19:24 +08:00
不好意思,@autoxbc 我更新了下图片。
autoxbc
2017-08-21 22:35:05 +08:00
选中 dom 元素可以看这个问答,高票答案给了好几个项目
https://stackoverflow.com/questions/742210/does-anyone-know-a-dom-inspector-javascript-library-or-plugin

后面从 dom 生成 png,大概先用 dom 生成 svg,然后画到 canvas 里,最后输出 png
http://blog.csdn.net/jaylongli/article/details/50216553
http://www.jianshu.com/p/092496e772d4
https://juejin.im/entry/58b91491570c35006c4f7fdf

从 google 的压缩代码里,只翻出一个 canvg 的项目说明,是其中一步的工具。
flowfire
2017-08-27 14:03:44 +08:00
{
let theShadow = document.createElement("div");
theShadow.style.pointerEvents = "none";
theShadow.style.position = "fixed";
theShadow.style.top = "0px";
theShadow.style.left = "0px";
theShadow.style.right = "0px";
theShadow.style.bottom = "0px";
theShadow.style.background = "rgba(0,0,0,.2)";
document.body.appendChild(theShadow);
document.addEventListener("mouseover", e => {
let dom = e.target;
let position = dom.getBoundingClientRect();
let X = position.left;
let Y = position.top;
let width = position.width;
let height = position.height;
let chosen = dom.cloneNode();
chosen.innerHTML = dom.innerHTML;
Array.prototype.forEach.call(theShadow.childNodes, dom => dom.remove());
chosen.style.position = "fixed";
chosen.style.top = Y + "px";
chosen.style.left = X + "px";
chosen.style.width = width + "px";
chosen.style.height = height + "px";
chosen.style.border = "solid 2px yellow";
chosen.style.background = "#FFF";
theShadow.appendChild(chosen);

});
}

一个简单的 demo,还有挺多 bug,但是大概思路就是这样的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/384647

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX