When you load jquery 1.8.2 with requirejs 2.1.1 - $(document).ready() and $(window).load() events starts to behave really weird.

Sometimes only one of them are fired sometimes both but in all cases they are fired after all content, images etc are loaded -.load() event.

Switching to jQuery 1.7.2 makes .load() work properly though .ready() acts as .load() and is never fired on real DOM ready event. Am I doing something wrong here or not only me having these issues?

Example (open console and refresh):

http://jsbin.com/epujom/5

Source:

http://jsbin.com/epujom/5/edit

EDIT: I have updated test case. Now it is clearly seen that jQuery.isReady = false even when DOM is ready

有帮助吗?

解决方案 2

The only way i can achieve a result i wanted is to load in the head section domready plugin like

https://github.com/freelancephp/DOMReady

or

https://github.com/requirejs/domReady

domready plugin or attaching events should always be ran before actual browser domready event occurs otherwise all of them are waiting for all images to be loaded and that is not what you want.

其他提示

RequireJS provides a lightweight domReady module that you can use alongside other modules. By doing so you take away the need to wait for jQuery to be loaded and parsed before dom ready functionality becomes available.

More detail - http://requirejs.org/docs/api.html#pageload

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top