我注意到,在我的 iphone5 上使用 safari
$(window).resize()
它的工作方式很奇怪......
我有这个代码:
$(document).ready(function () {
$(window).resize(function() {
avviaChart();
initialize();
if($('#time').is(':checked')){
$("#time").removeAttr('checked');
$("#Time").css('border','2px solid #ffffff');
}
});
});
此代码仅在窗口大小发生变化时才有效.... 与其他浏览器一起工作非常好,但与 safari 一起,如果我滚动页面,代码也可以工作(并且窗口的大小不会改变)...
怎么可能?哦
最佳答案
这是 iOS6 Safari 中发生的已知错误。调整大小事件在滚动时随机触发。还好it's not a jQuery issue.
This answer解决类似问题也可能会解决您的问题。
对于懒惰的人:
3Stripe发布了您应该“存储窗口宽度并检查它在继续您的 $(window).resize 函数之前是否实际更改”
他的代码片段:
jQuery(document).ready(function($) {
/* Store the window width */
var windowWidth = $(window).width();
/* Resize Event */
$(window).resize(function(){
// Check if the window width has actually changed and it's not just iOS triggering a resize event on scroll
if ($(window).width() != windowWidth) {
// Update the window width for next time
windowWidth = $(window).width();
// Do stuff here
}
// Otherwise do nothing
});
});
关于javascript - $(window).resize() 在 safari : why it works also if scroll window (but doesn't resize)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29940691/