我在页面上添加了Windows调整大小事件
每当页面大小更改时都会调用它。
但是当我使用jquery css更新页面内div元素的css值并设置动画时,它会自动触发Windows调整大小事件。
这仅适用于IE
我想防止通过动画或CSS方法在手动更改大小时执行resize事件
这是我的代码
调整窗口大小
window.onresize=function(){ ... };
用于div大小更改
$('div#divtest').css({ 'position': 'absolute', 'z-index': '1', 'background-color': '#f6f6f6' }).animate({
width: '20%',
height : $('div#divother').height() - 29
}, 0);
编辑:
我不想在调整大小事件中进行任何更改,原因是它在页面上有所不同,因此我必须在所有现有事件中进行更改
我有机会暂时将其关闭
最佳答案
您可以通过以下方式实现:
在应用css
动画之前,请设置一些标志,如下所示:
$('div#divtest').data("css_animation", true); //set the flag
$('div#divtest').css({ 'position': 'absolute', 'z-index': '1', 'background-color': '#f6f6f6' }).animate({
width: '20%',
height : $('div#divother').height() - 29
}, 0,function() {
// Animation complete.
$('div#divtest').data("css_animation", false); //reset the flag
});
在
resize
中,我们可以检查标志是否设置如下:window.onresize=function(){
var flagValue = $('div#divtest').data("css_animation"); //fetch the flag value
//don't do anything if resize is getting called via css animation
if(flagValue === true)
return;
...
};