【发布时间】:2014-03-07 15:15:32
【问题描述】:
固定位置的 div(带有文本“Din Score”和苹果的栏)没有停留在页面底部。这个 div 类 scrollingScoreBoard 使用了一个 javascript,它将在台式机和笔记本电脑视图上保持相对位置,但在移动视图上移动到固定位置。
但是,在三星 Galaxy S 和 S II 上,它并没有停留在底部。
对于这些特定的手机,我应该如何将其固定在底部?
真正的工作站点是here
HTC One X 与三星 Galaxy S 的比较
这就是我所拥有的:
HTML:
<div id="scrollingScoreBoard">
<div class="currentScoreBox">
<div class="currentScoreText">
<p>Din Score</p>
</div>
<div class="greenAppleContainer">
<img class="appleGreenActive" src="eimg/blankApple.png" alt="" >
<img class="appleGreenDefault" src="eimg/blankApple.png" alt="" >
<img class="appleGreenDefault" src="eimg/blankApple.png" alt="" >
<img class="appleGreenDefault" src="eimg/blankApple.png" alt="" >
<img class="appleGreenDefault" src="eimg/blankApple.png" alt="" >
</div>
</div>
</div>
CSS:
#scrollingScoreBoard{
width: 320px;
color: white;
position: relative !important;
bottom: 0px;
margin:auto;
text-align:center;
left:0;
right:0;
background-color:#163c15;
z-index:1000;
clear:both;
}
.currentScoreBox{
position:relative;
background:url(../eimg/head_bg.png) 0 0 repeat scroll transparent;
height:47px;
width:100%;
max-width:320px;
text-align:left !important;
}
.currentScoreText{
float:left;
padding: 2px 0 0 70px;
}
.currentScoreBox .greenAppleContainer{
float: left;
padding: 12px 0 0 12px;
}
@media screen and (max-width:640px) {
#scrollingScoreBoard{
width: 320px;
color: white;
position: fixed !important;
bottom: 0px;
margin:auto;
text-align:center;
left:0;
right:0;
background-color:#163c15;
z-index:1000;
clear:both;
}
}
@media screen and (max-width:420px) {
#scrollingScoreBoard{
width: 100%;
}
}
JS:
var sticky_offset;
$(document).ready(function() {
var original_position_offset = $('#scrollingScoreBoard').offset();
sticky_offset = original_position_offset.top;
$('#scrollingScoreBoard').css('position', 'relative');
});
$(window).scroll(function () {
var sticky_height = $('#scrollingScoreBoard').outerHeight();
var where_scroll = $(window).scrollTop();
var window_height = $(window).height();
if((where_scroll + window_height) > sticky_offset) {
$('#scrollingScoreBoard').css('position', 'relative');
}
if((where_scroll + window_height) < (sticky_offset + sticky_height)) {
$('#scrollingScoreBoard').css('position', 'fixed');
}
});
$(document).ready(function() {
window.scrollTo(0,1);
});
【问题讨论】:
-
您在此 div 的代码中与
position: ... !important;矛盾。这很脏,可能会混淆浏览器。顺便说一句,您没有在这里显示整个相关的 CSS。 -
现在我有了所有相关的 CSS。 :)
-
你看,我使用了媒体查询,并且它对不同的视口使用不同的位置。我很确定它们在相同的媒体查询条件下并不矛盾。如果现在我看到了,如果我删除了“!重要”,它不会转到移动视图的固定位置。
标签: javascript html css android-browser