mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
31 lines
586 B
JavaScript
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
|
|
};
|