Jquery toggle on window minimize

荒凉一梦 提交于 2020-01-04 09:25:39

问题


I have a div that toggles in and out of display when you click on another div. How could I modify my code so that when the user minimizes the whole browser window it automatically toggles, hiding the div from view so when the user un-minimizes window the div is no longer visible.


回答1:


Minimizing the window (or switching to another application) should fire the window.onblur event. Activating the window should fire window.onfocus

Implementation details may differ slightly between browsers but there seems to be no better way in default javascript (may be you can use some flash object if flash can detect minimizing/maximizing of the window to fire necessary events, but I'm not familiar with flash)




回答2:


From a quick search it looks like you can attach an event to the windows resize event, then call the required toggle functions from there as usual. I havnt actually tested the linked sample though...

$(window).bind('resize', function() { ....

http://snipplr.com/view/6284/jquery--window-on-resize-event/




回答3:


In JavaScript, there is no way to detect when a window is minimized.

You could try detecting a resize or blur event on the window, however those can be triggered by things other than a minimize.



来源:https://stackoverflow.com/questions/552118/jquery-toggle-on-window-minimize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!