$ ("#img"). Load (function () {...});
This is a method provided by jquery, but in IE there will be BUG,IE8 not supported, IE9 above the refresh will not be executed, only forced refresh to execute, so you cannot use the method provided by this jquery
Should use:
Only through the JS onload to trigger the event, of course, the triggered event code can use jquery code (however, IE8 also has a bug, normal refresh when the picture from the cache read, read faster than the code, resulting in the onload code can not be run, the workaround see continue to look down)
document.getElementById (' Topbanner '). onload =function() { varTop = $ (' #nav '). Offset (). Top; $ (window). Scroll (function() { varScroll =$ (document). ScrollTop (); varpos = scroll-top; if(Scroll >top) { $(' #nav '). CSS (' top ', pos + + ' px ')); } Else { $(' #nav '). CSS (' top ', ' 12px ')); }; });
Fully compatible with IE8:
//first, declare an empty image objectvarIMG =NewImage ();//The OnLoad event is called through an IMG object; an event handler is defined, not executed (similar to defining an event within a tag)Img.onload =function() { varTop = $ (' #nav '). Offset (). Top; $ (window). Scroll (function() { varScroll =$ (document). ScrollTop (); varpos = scroll-top; if(Scroll >top) { $(' #nav '). CSS (' top ', pos + + ' px ')); } Else { $(' #nav '). CSS (' top ', ' 12px ')); }; });}//The IMG object is then assigned a value of SRC, so that the IMG object has a specific direction before the OnLoad event is started. This will be compatible with IE8.IMG.SRC = document.getElementById (' Topbanner ')). src;$ (window). Resize (function() {Top= $ (' #nav '). Offset (). Top; $ (window). Scroll (function() { varScroll =$ (document). ScrollTop (); varpos = scroll-top; if(Scroll >top) { $(' #nav '). CSS (' top ', pos + + ' px ')); } Else { $(' #nav '). CSS (' top ', ' 12px ')); }; });});}
Execute JS code after the picture is loaded