/**
|
* 计算大小
|
*/
|
import EventEmitter from './eventEmitter';
|
export default class Sizes extends EventEmitter {
|
constructor() {
|
super();
|
this.width = document.body.clientWidth;
|
this.height = document.body.clientHeight;
|
this.device = document.body.clientWidth <= 968 ? 'mobile' : 'pc';
|
// 设备像素
|
this.pixelRatio = Math.min(window.devicePixelRatio, 2);
|
|
// 宽高变化
|
window.addEventListener('resize', () => {
|
// this.width = window.innerWidth;
|
// this.height = window.innerHeight;
|
|
this.width = document.body.clientWidth;
|
this.height = document.body.clientHeight;
|
this.pixelRatio = Math.min(window.devicePixelRatio, 2);
|
this.trigger('resize');
|
|
if(this.width < 968 && this.device !== 'mobile') {
|
this.device = 'mobile';
|
this.trigger('devicechange');
|
} else if(this.width >= 968 && this.device !== 'pc') {
|
this.device = 'pc';
|
this.trigger('devicechange');
|
}
|
});
|
}
|
}
|