Authored by biao

update for the calculation of layer position

... ... @@ -3,8 +3,7 @@
* @author: bikai<kai.bi@yoho.cn>
* @date: 2015/10/28
*/
var $ = require('jquery'),
security = require('../plugin/security');
var $ = require('jquery');
var $searchBox = $('.search-box'),
$box = $('.box'),
... ... @@ -44,9 +43,6 @@ $searchBox.children('.clear-text').on('touchstart', function() {
});
$searchBox.children('.search-icon').on('touchstart', function() {
if (security.hasDangerInput()) {
return false;
}
$indexSearch.submit();
});
... ... @@ -74,6 +70,7 @@ $channelLink.on('touchstart', function() {
});
var updateLayerPosition = (function() {
var init = false;
var windowViewHeight = 0;
return function() {
var winHeight = window.innerHeight;
var bodyHeight = $doc.height();
... ... @@ -82,11 +79,22 @@ var updateLayerPosition = (function() {
var layerPaddingTop = parseInt($appFloatLayer.css('padding-top'));
var layerPaddingBottom = parseInt($appFloatLayer.css('padding-bottom'));
var newPosition;
if(init){
newPosition = bodyHeight - winHeight- scrollTopPosition;
if (windowViewHeight - winHeight > 200){//keyboard is shown
newPosition = bodyHeight - winHeight - scrollTopPosition - (layerHeight + layerPaddingTop + layerPaddingBottom);
} else {
newPosition = bodyHeight - winHeight -scrollTopPosition;
}
if (scrollTopPosition + winHeight === bodyHeight) {
console.log('got end');
newPosition = 0;
}
}else{
init = true;
windowViewHeight = winHeight;
newPosition = bodyHeight - winHeight - scrollTopPosition + layerHeight + layerPaddingTop + layerPaddingBottom;
init = true;
}
$appFloatLayer.css({
'position': 'relative',
... ... @@ -96,8 +104,20 @@ var updateLayerPosition = (function() {
})();
$win.scroll(function() {
updateLayerPosition();
//clearTimeout($.data(this, 'scrollTimer'));
//$.data(this, 'scrollTimer', setTimeout(function() {
// updateLayerPosition();
//}, 2));
});
//$search.focusin(function() {
// $body.css('overflow','hidden');
//});
//
//$search.focusout(function() {
// $body.css('overflow','auto');
//});
$doc.on('ready', updateLayerPosition);
... ...