Skip to content

Commit e9b424e

Browse files
committedNov 30, 2015
解决微信下,后退时,页面滚动到顶部的问题
1 parent b615c82 commit e9b424e

File tree

11 files changed

+79
-11
lines changed

11 files changed

+79
-11
lines changed
 

‎dist/css/mui.css

+2
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,8 @@ select:focus
50135013
position: absolute;
50145014
right: 0;
50155015
left: 0;
5016+
5017+
-webkit-overflow-scrolling: touch;
50165018
}
50175019
.mui-iframe-wrapper iframe
50185020
{

‎dist/css/mui.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/js/mui.js

+21
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,27 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
19021902
iframe.name = iframe.id;
19031903
wrapper.appendChild(iframe);
19041904
document.body.appendChild(wrapper);
1905+
//目前仅处理微信
1906+
$.os.wechat && handleScroll(wrapper, iframe);
1907+
};
1908+
1909+
function handleScroll(wrapper, iframe) {
1910+
var key = 'MUI_SCROLL_POSITION_' + document.location.href + '_' + iframe.src;
1911+
var scrollTop = (parseFloat(localStorage.getItem(key)) || 0);
1912+
if (scrollTop) {
1913+
(function(y) {
1914+
iframe.onload = function() {
1915+
window.scrollTo(0, y);
1916+
};
1917+
})(scrollTop);
1918+
}
1919+
setInterval(function() {
1920+
var _scrollTop = window.scrollY;
1921+
if (scrollTop !== _scrollTop) {
1922+
localStorage.setItem(key, _scrollTop + '');
1923+
scrollTop = _scrollTop;
1924+
}
1925+
}, 100);
19051926
};
19061927
$(function() {
19071928
var classList = document.body.classList;

‎dist/js/mui.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/hello-mui/css/mui.css

+2
Original file line numberDiff line numberDiff line change
@@ -5013,6 +5013,8 @@ select:focus
50135013
position: absolute;
50145014
right: 0;
50155015
left: 0;
5016+
5017+
-webkit-overflow-scrolling: touch;
50165018
}
50175019
.mui-iframe-wrapper iframe
50185020
{

‎examples/hello-mui/css/mui.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/hello-mui/examples/setting.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<link rel="stylesheet" type="text/css" href="../css/feedback-page.css" />
160160
</head>
161161

162-
<body>
162+
<body class="mui-fullscreen">
163163
<!--页面主结构开始-->
164164
<div id="app" class="mui-views">
165165
<div class="mui-view">

‎examples/hello-mui/js/mui.js

+21
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,27 @@ Function.prototype.bind = Function.prototype.bind || function(to) {
19021902
iframe.name = iframe.id;
19031903
wrapper.appendChild(iframe);
19041904
document.body.appendChild(wrapper);
1905+
//目前仅处理微信
1906+
$.os.wechat && handleScroll(wrapper, iframe);
1907+
};
1908+
1909+
function handleScroll(wrapper, iframe) {
1910+
var key = 'MUI_SCROLL_POSITION_' + document.location.href + '_' + iframe.src;
1911+
var scrollTop = (parseFloat(localStorage.getItem(key)) || 0);
1912+
if (scrollTop) {
1913+
(function(y) {
1914+
iframe.onload = function() {
1915+
window.scrollTo(0, y);
1916+
};
1917+
})(scrollTop);
1918+
}
1919+
setInterval(function() {
1920+
var _scrollTop = window.scrollY;
1921+
if (scrollTop !== _scrollTop) {
1922+
localStorage.setItem(key, _scrollTop + '');
1923+
scrollTop = _scrollTop;
1924+
}
1925+
}, 100);
19051926
};
19061927
$(function() {
19071928
var classList = document.body.classList;

‎examples/hello-mui/js/mui.min.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎js/mui.init.js

+21
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@
9595
iframe.name = iframe.id;
9696
wrapper.appendChild(iframe);
9797
document.body.appendChild(wrapper);
98+
//目前仅处理微信
99+
$.os.wechat && handleScroll(wrapper, iframe);
100+
};
101+
102+
function handleScroll(wrapper, iframe) {
103+
var key = 'MUI_SCROLL_POSITION_' + document.location.href + '_' + iframe.src;
104+
var scrollTop = (parseFloat(localStorage.getItem(key)) || 0);
105+
if (scrollTop) {
106+
(function(y) {
107+
iframe.onload = function() {
108+
window.scrollTo(0, y);
109+
};
110+
})(scrollTop);
111+
}
112+
setInterval(function() {
113+
var _scrollTop = window.scrollY;
114+
if (scrollTop !== _scrollTop) {
115+
localStorage.setItem(key, _scrollTop + '');
116+
scrollTop = _scrollTop;
117+
}
118+
}, 100);
98119
};
99120
$(function() {
100121
var classList = document.body.classList;

‎sass/iframe.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.#{$namespace}iframe-wrapper{
2+
-webkit-overflow-scrolling:touch;
23
position: absolute;
34
left: 0;
45
right: 0;

0 commit comments

Comments
 (0)
Please sign in to comment.