我正在使用 debounce 函数来调整 div 的大小 - 它工作正常,除了在 IE 10 和 11 上,它似乎一直被调用,最终显示滚动条不断关闭和打开,并且 div “闪烁”。任何已知的解决方案?
谢谢。
很抱歉 - 这是功能:
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this,
args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
// 当背景大小改变时调整视频大小
var myResizingFn = debounce(function() {
if ((myPlayer !== null) && ($('#author-pane').length === 0) && (newDimensions !== null)) {
var tWidth = $(window).width();
newDimensions = calculateAspectRatioFit(theWidth, theHeight, tWidth , 10000);
s9.view.size({
width: "100%",
height: newDimensions.height
});
myPlayer.width(newDimensions.width);
myPlayer.height(newDimensions.height);
myPlayer.show();
}
}, 200);
$(window).on('resize', myResizingFn);