4

编辑:解决了文本问题,仍然需要 Firefox 转换的帮助。

向下滚动页面后尝试使用最小菜单。该代码在它正在转换的意义上起作用,但是它并没有像我希望的那样转换。有两个问题:

  1. 在 Chrome 中,只有在其他所有内容都移动后,文本才会“滑动”到中间。
  2. 在 Firefox 中,图像不会过渡/淡出,它只是简单地从右侧“打开”。

在理想情况下,我希望图像能够像在 Chrome 中那样进行动画处理,但我希望文本像在 Firefox 中那样滑动到位。

我在 Stackoverflow 和其他地方查找了其他问题,但似乎没有一个解决方案可以解决 Webkit 和 Moz 之间的差异。

jsFiddle的问题。

尝试这个:

$(document).on("scroll",function(){
        if($(document).scrollTop()>100){ 
            $(".logo").removeClass("logo_large").addClass("logo_small");
            $("header").removeClass("large").addClass("small");
            }
        else{
            $(".logo").removeClass("logo_small").addClass("logo_large");
            $("header").removeClass("small").addClass("large");
            }
        });
.small li, .large li, .logo_large, .logo_small {
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari and Chrome */
    -o-transition: all 1s; /* Opera */
}

nav {
    width: 960px;
    margin: 0 auto;
}

ul {
    display:inline-table;
    list-style-type: none;
    text-align: center;
}

li {
    display:table-cell;
    float: left;
    text-align: center;
    margin-right: 30px;
}

.large li {
    height: 120px;
    line-height: 120px;
}

.small li {
    height: 70px;
    line-height: 70px;
}

.logo_large {
    height: 130px;
    width: 164px;
    background:url(https://unsplash.it/200/300) no-repeat;
}

.logo_small {
    height: 80px;
    width: 50px;
    background:url(https://unsplash.it/200/300) no-repeat;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<header class="large">
    <nav>
        <ul>
            <li><a class="active" href="#">Home</a></li>
            <li><a href="#">Services</a></li>
            <li><a href="#">Portfolio</a></li>
            <li class="logo logo_large"></li>
            <li><a href="#">Blog</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</header>

4

2 回答 2

3

从实际元素中删除过渡header, a, img, li{...并添加到实际元素中:

.large li {
    height: 120px;
    line-height: 120px;
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari and Chrome */
    -o-transition: all 1s; /* Opera */
}

.small li {
    height: 70px;
    line-height: 70px;
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari and Chrome */
    -o-transition: all 1s; /* Opera */
}

.logo_large {
    height: 130px;
    width: 164px;
    background:url(http://samaradionne.com/img/typeBlack.png) no-repeat;
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari and Chrome */
    -o-transition: all 1s; /* Opera */
}

.logo_small {
    height: 80px;
    width: 50px;
    background:url(http://samaradionne.com/img/logoBlack.png) no-repeat;
    transition: all 1s;
    -moz-transition: all 1s; /* Firefox 4 */
    -webkit-transition: all 1s; /* Safari and Chrome */
    -o-transition: all 1s; /* Opera */
}
于 2013-04-10T00:07:08.630 回答
1

如果这是您仅有的两种状态,您可以通过创建持久类和覆盖类并将您的样式应用到这些状态来避免该问题,例如:

.logo { }
.logo.minimized { }

只需添加和删除覆盖样式。

这应该允许 jQuery 正确计算转换。

于 2013-04-09T23:33:10.477 回答