Javascript Css-移动定位固定的最终解决方案
我在手机上遇到了问题:Javascript Css-移动定位固定的最终解决方案,javascript,html,css,mobile,css-position,Javascript,Html,Css,Mobile,Css Position,我在手机上遇到了问题: <div class="sticky">sticky to bottom</div> .sticky{ position:fixed; bottom:0; right:0; left:0; width:100%; } 我已经遇到了这个问题,就像你一样,许多解决方案对我不好,然后我使用这种技术来让用户觉得很好: 如果滚动,请使用Javascript进行检测,然后隐藏块,直到滚动停止并再次显示。这是由于浏览器在手指放下时未发送滚动事件造成的,如果没
<div class="sticky">sticky to bottom</div>
.sticky{
position:fixed;
bottom:0;
right:0;
left:0;
width:100%;
}
我已经遇到了这个问题,就像你一样,许多解决方案对我不好,然后我使用这种技术来让用户觉得很好:
如果滚动,请使用Javascript进行检测,然后隐藏块,直到滚动停止并再次显示。这是由于浏览器在手指放下时未发送滚动事件造成的,如果没有大型Javascript库,您就无法真正对此做太多。我正在测试,但是滚动呢,i红色触摸设备在滚动停止之前不会触发滚动:/!?您可以使用以下事件:scrollstart和scrollstop来检测滚动是否停止:)哦,这很好,我会告诉您,如果没有其他好的答案,我会接受(如果有效ehe)@katch check我更新了我的问题,问题可能存在,我像你告诉我的那样尝试过,但是当scrollstop页面返回顶部显示粘滞元素时,它不会保持在相同的窗口y位置,难以置信的是,你必须使用.hide()和.show()进行更改,而不是fadeOut()和fadeIn(),因为这需要时间;)
$(window).on('scrollstart',function(){
$('.sticky').css('top','100%').fadeOut();
});
$(window).on('scrollstop',function(){
$('.sticky').css('top','100%').fadeIn();
});
(function(){
var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);
special.scrollstart = {
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
} else {
evt.type = 'scrollstart';
jQuery.event.handle.apply(_self, _args);
}
timer = setTimeout( function(){
timer = null;
}, special.scrollstop.latency);
};
jQuery(this).bind('scroll', handler).data(uid1, handler);
},
teardown: function(){
jQuery(this).unbind( 'scroll', jQuery(this).data(uid1) );
}
};
special.scrollstop = {
latency: 300,
setup: function() {
var timer,
handler = function(evt) {
var _self = this,
_args = arguments;
if (timer) {
clearTimeout(timer);
}
timer = setTimeout( function(){
timer = null;
evt.type = 'scrollstop';
jQuery.event.handle.apply(_self, _args);
}, special.scrollstop.latency);
};
jQuery(this).bind('scroll', handler).data(uid2, handler);
},
teardown: function() {
jQuery(this).unbind( 'scroll', jQuery(this).data(uid2) );
}
};
})();