Repository navigation
Expand file tree
/
Copy pathscroll-fix.js
More file actions
63 lines (52 loc) · 1.94 KB
/
Copy pathscroll-fix.js
File metadata and controls
63 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* ScrollFix v0.1
* http://www.joelambert.co.uk
*
* Copyright 2011, Joe Lambert.
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
/* ===============================================================================
************ ScrollFix ************
=============================================================================== */
+ function($) {
"use strict";
//安卓微信中使用scrollfix会有问题,因此只在ios中使用,安卓机器按照原来的逻辑
if($.device.ios){
var ScrollFix = function(elem) {
// Variables to track inputs
var startY;
var startTopScroll;
elem = elem || document.querySelector(elem);
// If there is no element, then do nothing
if(!elem)
return;
// Handle the start of interactions
elem.addEventListener('touchstart', function(event){
startY = event.touches[0].pageY;
startTopScroll = elem.scrollTop;
if(startTopScroll <= 0)
elem.scrollTop = 1;
if(startTopScroll + elem.offsetHeight >= elem.scrollHeight)
elem.scrollTop = elem.scrollHeight - elem.offsetHeight - 1;
}, false);
};
var initScrollFix = function(){
var prefix = $('.page-current').length > 0 ? '.page-current ' : '';
var scrollable = $(prefix + ".content");
new ScrollFix(scrollable[0]);
};
$(document).on($.touchEvents.move, ".page-current .bar",function(){
event.preventDefault();
});
//监听ajax页面跳转
$(document).on("pageLoadComplete", function(){
initScrollFix();
});
//监听内联页面跳转
$(document).on("pageAnimationEnd", function(){
initScrollFix();
});
initScrollFix();
}
}(Zepto);