【问题标题】:Can't vertically align text in animated div无法垂直对齐动画 div 中的文本
【发布时间】:2014-02-07 03:57:29
【问题描述】:

当我滚动以垂直居中显示我的文本时,我试图让我的标题缩小。对于我的生活,由于某种原因我无法弄清楚。

这里是网站http://work.nickmoyer.net 的链接。我正在使用 Bootstrap 3。我知道我忽略了一些愚蠢的东西,但我不能把手指放在它上面。

感谢您的帮助!

代码如下

导航栏

<div id="header_nav">
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
        <!-- Mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>

        <div class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#home" class="smoothScroll">Home</a></li>
                <li><a href="#services" class="smoothScroll">Services</a></li>
                <li><a href="<?php bloginfo('url'); ?>/portfolio/" class="smoothScroll">Portfolio</a></li>
                <li><a href="<?php bloginfo('url'); ?>/blog/" class="smoothScroll">Blog</a></li>
                <li><a href="#about" class="smoothScroll">About</a></li>
                <li><a href="#contact" class="smoothScroll">Contact</a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </nav>
</div>

Javascript 让 div 缩小

$(function(){
  $('#header_nav').data('size','big');
});

$(window).scroll(function(){
  if($(document).scrollTop() > 0)
{
    if($('#header_nav').data('size') == 'big')
    {
        $('#header_nav').data('size','small');
        $('#header_nav').stop().animate({
            height:'30px'
        },600);
    }
}
else
  {
    if($('#header_nav').data('size') == 'small')
      {
        $('#header_nav').data('size','big');
        $('#header_nav').stop().animate({
            height:'60px'
        },600);
      }  
  }
});

CSS

#header_nav .navbar-default {
    background-color:transparent !important;
    border-color:transparent !important;
}

.navbar-default {
    border-color:transparent !important;
}

#header_nav {
    width:100%;
    height:60px;
    position:fixed;
    background-color: rgb(248, 248, 248);
    top:0;
    left:0;
    z-index:10;
}

#header_nav li {
}

【问题讨论】:

  • 请在此处显示您的代码。
  • @isherwood 对此感到抱歉,现在在上面添加了

标签: html twitter-bootstrap-3 vertical-alignment


【解决方案1】:

我会这样做:

http://jsfiddle.net/isherwood/Ak42Z/

$('#header_nav').stop().animate({
    height: '30px'
}, 600).find('a.smoothScroll').stop().animate({
    padding: '5px 15px 0'
}, 600);

【讨论】:

  • 这无疑是朝着正确方向迈出的一步,但是当我向上滚动时,链接会粘在页面顶部并且不再居中。 work.nickmoyer.net
  • 此代码旨在在两个地方适合您的滚动逻辑。您需要根据需要将其反转。
【解决方案2】:

这是我在 js 文件中说完的代码

$(function(){
  $('#header_nav').data('size','big');
});

$(window).scroll(function(){
  if($(document).scrollTop() > 0)
{
    if($('#header_nav').data('size') == 'big')
    {
        $('#header_nav').data('size','small');
        $('#header_nav').stop().animate({
            height: '30px'
        }, 600).find('a.smoothScroll').stop().animate({
            padding: '5px 15px 0'
        }, 600);
    }
}
else
  {
    if($('#header_nav').data('size') == 'small')
      {
        $('#header_nav').data('size','big');
        $('#header_nav').stop().animate({
            height:'60px'
        },600).find('a.smoothScroll').stop().animate({
            padding: '15px 15px 0'
        }, 600);
      }  
  }
});


$

反正对我有用!

【讨论】:

  • 所以你拿走了我的代码,把它放在你的答案中,并在没有对我的答案投票的情况下授予自己接受?好的。只是检查。
猜你喜欢
  • 2022-01-19
  • 2020-03-27
  • 2012-12-09
  • 2017-01-17
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 2017-04-16
  • 1970-01-01
相关资源
最近更新 更多