Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
梁志锋
9 years ago
Commit
5290f25e677a124987b29502fdbc8c7c1feffb03
1 parent
e70906be
update RAF
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
1 deletions
static/js/common.js
static/js/product/detail/desc.js
static/js/common.js
View file @
5290f25
...
...
@@ -160,6 +160,48 @@ $header.on('touchstart', 'a', function() {
$
(
this
).
removeClass
(
'highlight'
);
});
(
function
()
{
var
lastTime
=
0
;
var
prefixes
=
'webkit moz ms o'
.
split
(
' '
);
var
requestAnimationFrame
=
window
.
requestAnimationFrame
;
var
cancelAnimationFrame
=
window
.
cancelAnimationFrame
;
var
prefix
;
//通过遍历各浏览器前缀,来得到requestAnimationFrame和cancelAnimationFrame在当前浏览器的实现形式
for
(
var
i
=
0
;
i
<
prefixes
.
length
;
i
++
)
{
if
(
requestAnimationFrame
&&
cancelAnimationFrame
)
{
break
;
}
prefix
=
prefixes
[
i
];
requestAnimationFrame
=
requestAnimationFrame
||
window
[
prefix
+
'RequestAnimationFrame'
];
cancelAnimationFrame
=
cancelAnimationFrame
||
window
[
prefix
+
'CancelAnimationFrame'
]
||
window
[
prefix
+
'CancelRequestAnimationFrame'
];
}
//如果当前浏览器不支持requestAnimationFrame和cancelAnimationFrame,则会退到setTimeout
if
(
!
requestAnimationFrame
||
!
cancelAnimationFrame
)
{
requestAnimationFrame
=
function
(
callback
,
element
)
{
var
currTime
=
new
Date
().
getTime
();
//为了使setTimteout的尽可能的接近每秒60帧的效果
var
timeToCall
=
Math
.
max
(
0
,
16
-
(
currTime
-
lastTime
)
);
var
id
=
window
.
setTimeout
(
function
()
{
callback
(
currTime
+
timeToCall
);
},
timeToCall
);
lastTime
=
currTime
+
timeToCall
;
return
id
;
};
cancelAnimationFrame
=
function
(
id
)
{
window
.
clearTimeout
(
id
);
};
}
window
.
requestAnimationFrame
=
requestAnimationFrame
;
window
.
cancelAnimationFrame
=
cancelAnimationFrame
;
}());
//暴露公共接口
window
.
cookie
=
cookie
;
...
...
static/js/product/detail/desc.js
View file @
5290f25
...
...
@@ -2,4 +2,69 @@
* 商品详情
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/11/18
*/
\ No newline at end of file
*/
var
$
=
require
(
'jquery'
),
Hammer
=
require
(
'yoho.hammer'
),
tip
=
require
(
'../plugin/tip'
),
loading
=
require
(
'../plugin/loading'
),
lazyLoad
=
require
(
'yoho.lazyload'
);
var
loading
=
require
(
'../../plugin/loading'
);
var
navHammer
,
winH
=
$
(
window
).
height
(),
searching
=
false
,
num
,
url
;
function
scrollHandler
()
{
if
(
$
(
window
).
scrollTop
()
+
winH
>=
$
(
document
).
height
()
-
50
)
{
//search();
}
}
function
search
()
{
if
(
searching
)
{
return
;
}
searching
=
true
;
loading
.
showLoadingMask
();
//num = $goodList.find('.good-info').length;
$
.
ajax
({
type
:
'GET'
,
url
:
url
,
data
:
{
page
:
page
+
1
},
success
:
function
(
data
)
{
num
=
$goodList
.
find
(
'.good-info'
).
length
;
$goodList
.
append
(
data
);
// 2015/10/31 fei.hong: 修复第一页分页不显示图片的问题
if
(
num
===
0
)
{
lazyLoad
(
$goodList
.
find
(
'.good-info'
).
find
(
'img.lazy'
));
}
else
{
lazyLoad
(
$goodList
.
find
(
'.good-info:gt('
+
(
num
-
1
)
+
')'
).
find
(
'img.lazy'
));
}
searching
=
false
;
loading
.
hideLoadingMask
();
page
++
;
},
error
:
function
()
{
tip
.
show
(
'网络断开连接了~'
);
searching
=
false
;
loading
.
hideLoadingMask
();
}
});
}
//srcoll to load more
$
(
window
).
scroll
(
function
()
{
window
.
requestAnimationFrame
(
scrollHandler
);
});
...
...
Please
register
or
login
to post a comment