vant-weapp/docs/src/utils.js
2018-08-10 11:09:24 +08:00

31 lines
586 B
JavaScript

function iframeReady(iframe, callback) {
const doc = iframe.contentDocument || iframe.contentWindow.document;
const interval = () => {
if (iframe.contentWindow.switchImage) {
callback();
} else {
setTimeout(() => {
interval();
}, 50);
}
};
if (doc.readyState === 'complete') {
interval();
} else {
iframe.onload = interval;
}
}
function syncPath(path) {
const iframe = document.querySelector('iframe');
iframeReady(iframe, () => {
iframe.contentWindow.switchImage(path);
});
}
export {
syncPath,
iframeReady
};