wengjq / share Goto Github PK
View Code? Open in Web Editor NEW线下分享的记录(ppt)
线下分享的记录(ppt)
问题:如何生成多个 Layer ?(layer.html)
一层 Layer VS 两层 Layer
一般来说,拥有相同的坐标空间的 节点 属于同一个渲染层。渲染层最初是用来实现层叠上下文,以此来保证页面元素以正确的顺序合成(composite),这样才能正确的展示元素的重叠以及半透明元素等
特殊的渲染层。合成层是单独的”层”,“层”的上下文会负责输出该层的位图,位图是存储在共享内存中,作为纹理上传到 GPU 中,最后由 GPU 将多个位图进行合成,然后画到屏幕
先是渲染层,然后满足一些条件可以提升成合成层
如果多个渲染层同一个合成层重叠时,这些渲染层会被压缩到一个合成层中,以防止由于重叠原因导致可能出现的“层爆炸”(layer-squash.html)
不能压缩的情况:
可以理解为重绘或重画,当渲染树中的一些元素需要更新属性,而这些属性只是影响元素的外观,风格,而不会影响布局的,例如改变背景颜色 。则就叫称为重绘。
可以理解为回流、布局或者重排,当渲染树中的一部分(或全部)因为元素的尺寸,布局,隐藏等改变而需要重新构建。这就称为回流(reflow),也就是重新布局(relayout)。
回流的代价比重绘的代价高很多,重绘会影响部分的元素,而回流则有可能影响全部的元素。反复执行回流,会页面渲染效率变低,甚至造成页面“卡顿”。(animation.html)
有些浏览器对于频繁的 DOM 操作会设置脚本所需更改的队列,并分批执行。每个需要 Reflows 的几个变化将被组合,并且将仅计算一个 Reflows。
虽然浏览器会有合并 Reflow 的优化,但有时脚本可能会阻止浏览器优化 Reflows,并使其刷新队列并执行所有批量更改。当您请求如下样式信息时(并非包含全部),会发生这种情况(reflow.html)
演示查浏览器的”卡顿“问题及定位(animation.html , animation-optimize.html)
Q&A
现有的页面统计基本都是在页面具体的 dom 节点处插入 js 代码执行,如 Mobi.logDog(xxx, xxx); 等。
由于没有好的规范,有的直接是在 dom0 级事件上写,有的在 js 绑定点击事件执行,有的在 vue 实例的方法写,这种埋点方式分布散乱,不利于维护和统计。
混入 (mixins) 是一种分发 Vue 组件中可复用功能的非常灵活的方式。混入对象可以包含任意组件选项。当组件使用混入对象时,所有混入对象的选项将被混入该组件本身的选项。
例子:
// 同名钩子函数将混合为一个数组,因此都将被调用。另外,混入对象的钩子将在组件自身钩子之前调用。
var mixin = {
created: function () {
console.log('混入对象的钩子被调用')
}
}
new Vue({
mixins: [mixin],
created: function () {
console.log('组件钩子被调用')
}
});
// => "混入对象的钩子被调用"
// => "组件钩子被调用"
// 值为对象的选项,例如 methods, components 和 directives,将被混合为同一个对象。两个对象键名冲突时,取组件对象的键值对。
var mixin = {
methods: {
foo: function () {
console.log('foo')
},
conflicting: function () {
console.log('from mixin')
}
}
}
var vm = new Vue({
mixins: [mixin],
methods: {
bar: function () {
console.log('bar')
},
conflicting: function () {
console.log('from self')
}
}
})
vm.foo() // => "foo"
vm.bar() // => "bar"
vm.conflicting() // => "from self"
var captrueContexts = [];
Vue.mixin({
mounted: function() {
var _this = this;
captrueContexts.push(this);
this.$nextTick(function() {
delegateBehavior(_this);
});
}
});
function delegateBehavior(context) {
var _this = context;
var eventTypes = ['click', 'change']; // 绑定事件数组
// 实例根元素绑定事件
// 每个 vue 实例的 $root 代表它的根节点,_isBindDelegate 判断是否绑定过事件
if (context.$root.$el && !context.$root.$el._isBindDelegate) {
eventTypes.forEach(function (eventType) {
context.$root.$el.addEventListener(eventType, function(e) {
var $target = $(e.target);
_this.captrue(e, captrueContexts, eventType);
}, true); // addEventListener 的第三个参数使用 true ,使用捕获,而不是冒泡
});
context.$root.$el._isBindDelegate = true;
}
}
methods: {
captrue: function(e, captrueContexts, eventType) {
var els = captrueContexts.map(function(context) {
return context.$el;
});
var currentEl = e.target;
while (currentEl) {
var index = els.indexOf(currentEl);
if (index > -1) {
// 触发事件
this.$emit('logreport', e, captrueContexts, index, eventType);
break;
}
currentEl = currentEl.parentNode;
}
}
}
this.$on('logreport', function (e, captrueContexts, index, eventType) {
var comp = captrueContexts[index]; // 获取当前组件
var elm = comp._vnode.elm; // 获取组件元素
// 拼装 log 逻辑...
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.