In the picture after the success of the load can be added to the appropriate display (example in the wood is reflected, you can try to find a lot of source code on the Internet, but are false, is not to achieve what we want to save the browser resources of the code, the following I have to modify their own and reference to the realizes the true visual area loading picture method. Implement website Http://www.111cn.net
JavaScript source code is as follows:
var scrollload = (function (options) {
var defaults = (Arguments.length = = 0)? {src: ' xsrc ', time:300}: {SRC:OPTIONS.SRC | | ' Xsrc ', Time:options.time | | 300};
var camelize = function (s) {
Return S.replace (/-(w)/g, function (Strmatch, p1) {
return P1.touppercase ();
});
};
This.getstyle = function (element, property) {
if (arguments.length!= 2) return false;
var value = Element.style[camelize (property)];
if (!value) {
if (Document.defaultview && document.defaultView.getComputedStyle) {
The var css tutorial = Document.defaultView.getComputedStyle (element, NULL);
Value = CSS? Css.getpropertyvalue (property): null;
else if (Element.currentstyle) {
Value = Element.currentstyle[camelize (property)];
}
}
return value = = ' Auto '? ': value;
};
var _init = function () {
var offsetpage = Window.pageyoffset? Window.pageYOffset:window.document.documentElement.scrollTop,
Offsetwindow = offsetpage + number (window.innerheight? window.innerHeight:document.documentElement.clientHeight),
Docimg = Document.images,
_len = Docimg.length;
if (!_len) return false;
for (var i = 0; i < _len; i++) {
var attrsrc = Docimg[i].getattribute (DEFAULTS.SRC),
o = docimg[i], tag = O.nodename.tolowercase ();
if (o) {
Postpage = O.getboundingclientrect (). Top + Window.document.documentElement.scrollTop + Window.document.body.scrollTop; Postwindow = postpage + number (This.getstyle (o, ' height '). Replace (' px ', '));
if ((Postpage > Offsetpage && postpage < Offsetwindow) | | (Postwindow > Offsetpage && postwindow < Offsetwindow)) {
if (tag = = "img" && attrsrc!== null) {
O.setattribute ("src", attrsrc);
}
o = null;
}
}
};
Window.onscroll = function () {
settimeout (function () {
_init ();
}, Defaults.time);
}
};
return _init ();
});
Scrollload ();
Dynamically changed to SRC value
Scrollload ({
SRC: ' usersrc ',//String type
TIME:100//Digital type
})