首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(响应jQuery)分区未填充浏览器高度

(响应jQuery)分区未填充浏览器高度
EN

Stack Overflow用户
提问于 2014-01-26 04:18:58
回答 3查看 110关注 0票数 0

我做了一些jQuery全页滑动面板,在桌面上看起来很完美,但是当浏览器向下调整大小时,面板div就不会填充页面。

JSFiddle是查看的最简单方法(只需向下调整预览窗口的大小):小提琴

HTML:

代码语言:javascript
复制
<div class="window">
<div class="panel-1" id="one">
    <p>Lorem</p>
    <div class="nav">Jump To:
       <a href="#" id="1one">1</a>  <a href="#" id="1two">2</a>  <a href="#" id="1three">3</a>
    </div>
</div>
<div class="panel-2" id="two">
    <p>Lorem</p>
    <div class="nav">Jump To:
        <a href="#" id="2one">1</a>  <a href="#" id="2two">2</a>  <a href="#" id="2three">3</a>
    </div>
</div>
<div class="panel-3" id="three">
    <p>Lorem</p>
    <div class="nav">Jump To:
        <a href="#" id="3one">1</a>  <a href="#" id="3two">2</a>  <a href="#" id="3three">3</a>
    </div>
</div>

CSS:

代码语言:javascript
复制
body {
     margin:0;
     padding:0;
 }
 .window {
     width: 100%;
     margin: 0 auto;
     overflow: hidden;
     position: fixed;
 }
 [class^="panel"] {
     height: 100%;
     text-align: center;
     position: absolute;
     transition: all ease 1s;
     -o-transition: all ease 1s;
     -moz-transition: all ease 1s;
     -webkit-transition: all ease 1s;
 }
 .panel-1 {
     background: gray;
 }
 .panel-2 {
     background: GoldenRod;
     margin-top:100%;
 }
 .panel-3 {
     background: green;
     margin-top:100%;
 }

JS (jQuery):

代码语言:javascript
复制
// Controls panel movement
$(document).ready(function () {
    $('#1two').click(function () {
        $('.panel-2').css('margin-top', '0');
    });
    $('#1three').click(function () {
        $('.panel-3').css('margin-top', '0');
        $('.panel-2').css('margin-top', '0');
    });
    $('#1one').click(function () {
        $('.panel-3').css('margin-top', '100%');
        $('.panel-2').css('margin-top', '100%');
    });
    $('#2two').click(function () {
        $('.panel-2').css('margin-top', '0');
    });
    $('#2three').click(function () {
        $('.panel-3').css('margin-top', '0');
    });
    $('#2one').click(function () {
        $('.panel-3').css('margin-top', '100%');
        $('.panel-2').css('margin-top', '100%');
    });
    $('#3two').click(function () {
        $('.panel-2').css('margin-top', '0');
        $('.panel-3').css('margin-top', '100%');
    });
    $('#3three').click(function () {
        $('.panel-3').css('margin-top', '0');
    });
    $('#3one').click(function () {
        $('.panel-3').css('margin-top', '100%');
        $('.panel-2').css('margin-top', '100%');
    });
});

// Forces "window" <div> to full page height
$(function () {
    $('.window').css({
        'height': (($(window).height())) + 'px'
    });
    $(window).resize(function () {
        $('.window').css({
            'height': (($(window).height())) + 'px'
        });
    });
});

任何帮助都将不胜感激!小提琴

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-01-26 04:31:29

您的问题是由于使用margin-top动画和定位面板上/关闭屏幕。由于面板都处于绝对位置,所以只需使用top声明,如下所示:

代码语言:javascript
复制
$(document).ready(function () {
    $('#1two').click(function () {
        $('.panel-2').css('top', '0');
    });
    $('#1three').click(function () {
        $('.panel-3').css('top', '0');
        $('.panel-2').css('top', '0');
    });
    $('#1one').click(function () {
        $('.panel-3').css('top', '100%');
        $('.panel-2').css('top', '100%');
    });
    $('#2two').click(function () {
        $('.panel-2').css('top', '0');
    });
    $('#2three').click(function () {
        $('.panel-3').css('top', '0');
    });
    $('#2one').click(function () {
        $('.panel-3').css('top', '100%');
        $('.panel-2').css('top', '100%');
    });
    $('#3two').click(function () {
        $('.panel-2').css('top', '0');
        $('.panel-3').css('top', '100%');
    });
    $('#3three').click(function () {
        $('.panel-3').css('top', '0');
    });
    $('#3one').click(function () {
        $('.panel-3').css('top', '100%');
        $('.panel-2').css('top', '100%');
    });
});

另外,一定要更新CSS:

代码语言:javascript
复制
 .panel-1 {
     background: gray;
 }
 .panel-2 {
     background: GoldenRod;
     top:100%;
 }
 .panel-3 {
     background: green;
    top: 100%;
 }
/* Nav */
 .nav {
    background:black;
    color:yellow;
    bottom:0;
    position:absolute;
    width:100%;
}

这是您最新的小提琴

票数 0
EN

Stack Overflow用户

发布于 2014-01-26 04:54:16

嗨,我更新了小提琴。只需检查它是否正常工作。

http://jsfiddle.net/ejqLy/8/

代码语言:javascript
复制
 .nav {
background:black;
color:yellow;
bottom:0;
position:absolute;
width:100%;

}

与洗牌动画:

JS小提琴

票数 0
EN

Stack Overflow用户

发布于 2014-01-26 04:34:13

div的高度看起来不错,但是您的.nav需要定位到底部,如下所示:jsfiddle.net/ejqLy/6

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21359634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档