-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() –