简体   繁体   English

当我最大化窗口或返回窗口模式时,$(window).resize()事件在Chrome中不起作用

[英]$(window).resize() event doesn't work in Chrome when i maximize window or back in windowed mode

The following function, containing a "resize" event, works fine when i resize the window by dropping a border with the mouse, but when i maximize the browser or i restore the window the script doesn't work. 以下函数,包含“调整大小”事件,通过使用鼠标删除边框来调整窗口大小时工作正常,但是当我最大化浏览器或我恢复窗口时脚本不起作用。 It works fine in the other browsers. 它在其他浏览器中工作正常。

What could be the reason? 可能是什么原因?

(function ( $ ) {
    jQuery.fn.font_resizer = function () {
        var self = jQuery(this);
        var fontSize = self.css('fontSize').slice(0, -2);
        var lineH = self.css('lineHeight').slice(0, -2);
        jQuery(self).resize_font(self, fontSize, lineH);

        jQuery(window).on('resize', function() {
           jQuery(self).resize_font(self, fontSize, lineH);
        });
    };
    } (jQuery));

This works for me on Chrome Version 42.0.2311.90 m. 这适用于Chrome版本42.0.2311.90 m。

jQuery(window).on('resize', function() {...} Works on window maximize as well as on resizing the window borders. It does not work on window minimize/restore, since the size does not change, so this shouldn't affect you. jQuery(window).on('resize', function() {...}适用于窗口最大化以及调整窗口边框大小。它不适用于窗口最小化/恢复,因为大小不会改变,所以这不应该影响你。

JSFiddle: https://jsfiddle.net/seadonk/jafdoex8/ JSFiddle: https ://jsfiddle.net/seadonk/jafdoex8/

I did not see the declaration of your font_resize event, so I made my own, that just sets the font size and line height according to window width and height. 我没有看到你的font_resize事件的声明,所以我自己做了,只根据窗口宽度和高度设置字体大小和行高。

(function ($) {
    jQuery.fn.font_resizer = function () {
        var self = $(this);
        var fontSize = self.css('fontSize').slice(0, -2);
        var lineH = self.css('lineHeight').slice(0, -2);
        jQuery(self).resize_font(fontSize, lineH);
        jQuery(window).on('resize', function () {
            jQuery(self).resize_font(fontSize, lineH);
        });
    };

    //on window resize set the font and line height
    jQuery.fn.resize_font = function (fontSize, lineH) {        
        var self = $(this);
        self.css('fontSize',$(window).width()/1920*36+'pt');
        self.css('line-Height',$(window).height()/1080*36+'px');
        $('#fontSize').text(self.css('fontSize').slice(0, -2));
        $('#lineHeight').text(self.css('lineHeight').slice(0, -2));
        $('#fontTimeStamp').text(getTime());
    };
}(jQuery));

(function () {
    $("body").font_resizer();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM