javascript - 在 Samsung Galaxy S 和 S II 上固定位置

标签 javascript html css android-browser

固定位置的 div(带有文本“Din Score”和其中的苹果的栏)没有停留在页面底部。此 div 类 scrollingScoreBoard 使用 javascript,它将在桌面和笔记本电脑 View 中保持相对定位,但在移动 View 中将移动到固定位置。

但是,在 Samsung Galaxy S 和 S II 上,它不会停留在底部。

我应该如何将它固定在这些特定手机的底部?

真正的工作地点是 here

HTC One X 与三星 Galaxy S 对比

enter image description here

这就是我所拥有的:

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);
            });

最佳答案

我遇到了同样的问题。我可以建议你的是,使用窗口调整大小。 我没有尝试那个 fiddle ,但关键是当你的窗口调整大小时,重新启动粘性栏脚本。

$(window).resize(function(){
    var original_position_offset = $('#scrollingScoreBoard').offset();
    sticky_offset = original_position_offset.top;
    $('#scrollingScoreBoard').css('position', 'relative');
};

关于javascript - 在 Samsung Galaxy S 和 S II 上固定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21674691/

相关文章:

javascript - 使用 JavaScript 读取缓存

javascript - 将硬编码行添加到 AngularJS 表选项

javascript - HTML5 从嵌套的 iframe 调整顶级文档 iframe 的大小

css - 如何删除列表项上的箭头。我只需要2017年的箭头

html - IE7显示父子背景图片问题

javascript - 将 transform-origin 移回 CSS 中元素的中心

javascript - document.write - 我的内容在哪里?

javascript - CouchdB Jquery Ajax POST CORS

html - 我们可以在html中制作自己的标签吗

css - Selenium XPATH 或 CSS 从 html 表中选择一个带有指定文本的复选框我选择了四个复选框