我有自定义控件按钮,用于打开我的过滤器。当屏幕改变时,自定义控件按钮必须处于其他位置。
我写了那段代码
window.onresize = () => {
if (screen.width <= 900) {
this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push($controlsTabs);
}
}
我收到错误
Uncaught TypeError: Cannot read property 'parentNode' of undefined
这是因为$controlsTabs
没有LEFT_TOP位置。
如何编写正确的代码?
答案 0 :(得分:0)
我决定了问题
window.onresize = () => {
if (screen.width <= 900) {
this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push($controlsTabs);
} else {
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.LEFT_TOP].push($controlsTabs);
}
google.maps.event.addDomListener(window, 'resize', () => {
google.maps.event.trigger(this.map, 'resize');
});
};