Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
s_ibanshou
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋林
s_ibanshou
Commits
7797d073
Commit
7797d073
authored
Nov 11, 2017
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页图片懒加载
parent
7190b4e2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
lazyload.js
skin/default/js/lazyload.js
+50
-0
No files found.
skin/default/js/lazyload.js
0 → 100644
View file @
7797d073
$
.
fn
.
lazyload
=
function
(
container
,
fn
)
{
if
(
typeof
container
==
"function"
)
{
fn
=
container
;
container
=
null
;
}
if
(
!
container
)
container
=
window
;
container
=
$
(
container
);
if
(
!
fn
)
fn
=
$
.
noop
;
var
cache
=
[];
//Cached
$
(
this
).
each
(
function
()
{
var
tag
=
this
.
nodeName
.
toLowerCase
(),
url
=
$
(
this
).
data
(
"src"
);
if
(
url
)
cache
.
push
({
obj
:
this
,
tag
:
this
.
nodeName
.
toLowerCase
(),
url
:
url
});
if
(
tag
==
"img"
&&
!
$
(
this
).
attr
(
"src"
))
$
(
this
).
attr
(
"src"
,
"data:image/gif;base64,R0lGODlhAQABAIAAAOjo6AAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw=="
);
});
function
check
()
{
var
contHeight
=
container
.
height
();
var
contop
=
container
.
get
(
0
)
===
window
?
container
.
scrollTop
()
:
container
.
offset
().
top
;
$
.
each
(
cache
,
function
(
i
,
data
)
{
if
(
!
data
.
obj
)
return
;
var
o
=
$
(
data
.
obj
),
url
=
data
.
url
;
var
post
=
o
.
offset
().
top
-
contop
;
var
posb
=
post
+
o
.
height
();
if
(
o
.
is
(
':visible'
)
&&
(
post
>=
0
&&
post
<
contHeight
)
||
(
posb
>
0
&&
posb
<=
contHeight
))
{
if
(
data
.
tag
===
"img"
)
{
fn
.
call
(
o
.
attr
(
"src"
,
url
)[
0
]);
}
else
{
o
.
load
(
url
,
{},
function
()
{
fn
.
call
(
o
[
0
]);
});
}
data
.
obj
=
null
;
}
});
}
check
();
container
.
on
(
"scroll"
,
check
);
return
this
;
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment