解决加入购物车弹窗出现时,页面滑动问题. code review by LZF
Showing
1 changed file
with
19 additions
and
0 deletions
@@ -32,6 +32,7 @@ var $chosePanel = $('#chose-panel'), | @@ -32,6 +32,7 @@ var $chosePanel = $('#chose-panel'), | ||
32 | queryString, | 32 | queryString, |
33 | $yohoPage = $('.yoho-page'); | 33 | $yohoPage = $('.yoho-page'); |
34 | 34 | ||
35 | + | ||
35 | //初始化购物车面板显示 | 36 | //初始化购物车面板显示 |
36 | function init() { | 37 | function init() { |
37 | hasChooseColor = false; | 38 | hasChooseColor = false; |
@@ -60,7 +61,19 @@ function checkColorSizeNum() { | @@ -60,7 +61,19 @@ function checkColorSizeNum() { | ||
60 | return true; | 61 | return true; |
61 | } | 62 | } |
62 | 63 | ||
64 | + | ||
63 | function show(html, cb) { | 65 | function show(html, cb) { |
66 | + var scrollPosition = [ | ||
67 | + document.documentElement.scrollLeft || document.body.scrollLeft, | ||
68 | + document.documentElement.scrollTop || document.body.scrollTop | ||
69 | + ], | ||
70 | + $html = $('html'); // it would make more sense to apply this to body, but IE7 won't have that | ||
71 | + | ||
72 | + $html.data('scroll-position', scrollPosition); | ||
73 | + $html.data('previous-overflow', $html.css('overflow')); | ||
74 | + $html.css('overflow', 'hidden'); | ||
75 | + window.scrollTo(scrollPosition[0], scrollPosition[1]); | ||
76 | + | ||
64 | if (html) { | 77 | if (html) { |
65 | $chosePanel.html(html); | 78 | $chosePanel.html(html); |
66 | if ($('#promotionId').val() !== '') { | 79 | if ($('#promotionId').val() !== '') { |
@@ -76,6 +89,12 @@ function show(html, cb) { | @@ -76,6 +89,12 @@ function show(html, cb) { | ||
76 | 89 | ||
77 | //隐藏当前Panel | 90 | //隐藏当前Panel |
78 | function hide() { | 91 | function hide() { |
92 | + var $html = $('html'), | ||
93 | + scrollPosition = $html.data('scroll-position'); | ||
94 | + | ||
95 | + // un-lock scroll position | ||
96 | + $html.css('overflow', $html.data('previous-overflow')); | ||
97 | + window.scrollTo(scrollPosition[0], scrollPosition[1]); | ||
79 | $('.chose-panel').hide(); | 98 | $('.chose-panel').hide(); |
80 | } | 99 | } |
81 | 100 |
-
Please register or login to post a comment