-1
所以,我有一个是通过选择jQuery对象返回undefined
$(window).scroll(function() {
console.log($("#content div").inview());
});
但是它返回undefined调用的函数。当我返回$ elems时,它向我显示了所有正确的元素,但是当我返回$ el时,它会给出未定义的元素。
$.fn.inview = function() {
var $elems = this;
function getViewportHeight() {
/*do tsoomething that works*/
return height;
}
var vpH = getViewportHeight(),
scrolltop = (document.documentElement.scrollTop ?
document.documentElement.scrollTop :
document.body.scrollTop);
// return $elems.toArray();
$elems.each(function() {
var $el = $(this)
height = $el.height() - (vpH/1.5),
inview = $el.data('inview') || false,
topofscreen = scrolltop,
botofscreen = topofscreen + vpH,
topofelement= $el.offset().top;
return $el;
};
[使用jQuery.each()时返回值的可能重复?](http://stackoverflow.com/questions/3820269/return-a-value-when-using-jquery-each) – JJJ
'return $ elems.each(...);'from $ .fn.inview() –