You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
794 B
30 lines
794 B
4 years ago
|
import { game } from './config';
|
||
|
|
||
|
let frame = document.getElementById('iframe');
|
||
|
let contentWindow = frame.contentWindow;
|
||
|
|
||
|
// 设置iframe框架的样式
|
||
|
export function setFrameStyle() {
|
||
|
const html = document.documentElement;
|
||
|
frame.style.width = html.clientWidth + 'px';
|
||
|
frame.style.height = Math.round(html.clientWidth * game.height / game.width) + 'px';
|
||
|
}
|
||
|
|
||
|
export function handleEventButtons() {
|
||
|
const eventButtons = document.querySelectorAll('div.events button');
|
||
|
|
||
|
eventButtons.forEach(item => {
|
||
|
item.addEventListener('click', function () {
|
||
|
sendMessage(item.dataset.event);
|
||
|
})
|
||
|
})
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 发送消息
|
||
|
* @param {string} type 消息类型
|
||
|
*/
|
||
|
function sendMessage(type) {
|
||
|
contentWindow.postMessage({ event: 'start' }, frame.src);
|
||
|
}
|