// 获取图片方向延时器 getImageOrientationTimer(context) { if (context.imageTimeout) return; if (context.imageOrientation) { context.imageTimeout = true; if (context.screenOrientation === 'portrait') { // 竖屏 context.portraitSwiperSet(); } else if (context.screenOrientation === 'landscape') { // 横屏 context.landscapeSwiperSet(); } } setTimeout(context.getImageOrientationTimer(context), 100); //getImageOrientationTimer是指自己,延时递归调用本身,100为间隔调用时间,单位毫秒 }
js实现定时器的另外一种方式,可是感受跟写setInterval差不太多,都有可能致使堆栈溢出的问题。不建议代码中使用。spa