- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
以下片段几乎是我目前元素的逐字复制(我已经将超棒的字体换成了问号,并且图像有所不同)。
我试图通过滚动使导航栏淡入淡出,为了防止“不可见”菜单项可点击,我需要设置 visibilty: hidden;
给他们。
过渡在向上滚动时效果很好,但在向下滚动时,即使我在 CSS 中添加了延迟,可见性过渡也会立即发生。我一辈子都想不通这个问题。我错过了什么吗?
var minHeaderHeight = 100; // Height of shrunken header, in pixels
var header = document.querySelector("#header"); // The header object
var maxHeaderHeight = outerHeight(header, true); // Height of expanded header, in pixels
document.addEventListener("DOMContentLoaded", initHeader);
function initHeader() {
var landingImage = document.getElementById("landing-image");
if (landingImage !== null) {
header.classList.add("expanded");
window.addEventListener('scroll', scrollCallback);
} else {
header.parentNode.style.paddingTop = minHeaderHeight + "px";
}
}
function scrollCallback() {
var scrollOffset = windowScrollTop();
var transitionEvent;
if (scrollOffset > 10) {
header.classList.remove("expanding");
header.classList.add("shrinking");
header.classList.remove("expanded");
} else {
header.classList.remove("shrinking");
header.classList.add("expanding");
header.classList.add("expanded");
}
}
// THESE TWO FUNCTIONS REPLICATE SIMILAR FUNCTIONS FROM JQUERY
function outerHeight(el, withMargins) {
withMargins = withMargins || false;
if (withMargins) {
var height = el.offsetHeight;
var style = getComputedStyle(el);
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
return height;
} else {
return el.offsetHeight;
}
}
function windowScrollTop(pos) {
if (typeof pos === 'undefined') {
if (window.pageYOffset !== undefined) {
return window.pageYOffset;
} else {
return (document.documentElement || document.body.parentNode || document.body).scrollTop;
}
} else {
document.documentElement.scrollTop = pos;
document.body.parentNode.scrollTop = pos;
document.body.scrollTop = pos;
window.pageYOffset = pos;
}
}
#header {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
justify-content: space-around;
align-items: center;
background-color: #000;
height: 100px;
text-transform: uppercase;
font-size: 2em;
color: white;
}
#header a {
color: white;
text-decoration: none;
}
#header-inner {
width: 100%;
z-index: 1;
display: flex;
justify-content: space-around;
align-items: center;
}
#header.expanded {
height: 100vh;
background-color: transparent;
}
#header.expanding {
-webkit-transition: height 300ms ease-in-out, background 300ms ease-in;
-moz-transition: height 300ms ease-in-out, background 300ms ease-in;
-ms-transition: height 300ms ease-in-out, background 300ms ease-in;
-o-transition: height 300ms ease-in-out, background 300ms ease-in;
transition: height 300ms ease-in-out, background 300ms ease-in;
}
#header.shrinking {
-webkit-transition: height 300ms ease-in-out, background 300ms ease-in;
-moz-transition: height 300ms ease-in-out, background 300ms ease-in;
-ms-transition: height 300ms ease-in-out, background 300ms ease-in;
-o-transition: height 300ms ease-in-out, background 300ms ease-in;
transition: height 300ms ease-in-out, background 300ms ease-in;
}
#header-logos {
position: relative;
}
#header-logos img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-height: 100px;
}
#header.shrinking img {
-webkit-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-moz-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-ms-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-o-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
}
#header.expanding img {
-webkit-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-moz-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-ms-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-o-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
}
.header-button {
-webkit-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-moz-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-ms-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-o-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
}
#header.expanded .header-button {
opacity: 0;
visibility: hidden;
-webkit-transition: visibility 0ms linear 300ms;
-moz-transition: visibility 0ms linear 300ms;
-ms-transition: visibility 0ms linear 300ms;
-o-transition: visibility 0ms linear 300ms;
transition: visibility 0ms linear 300ms;
}
#header-logo-top {
opacity: 0;
}
#header.expanded #header-logo-top {
opacity: 1;
}
#header.expanded img {
max-height: 500px;
}
#landing-image {
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#landing-image.home-page {
background-image: url("https://upload.wikimedia.org/wikipedia/commons/2/2f/KANTHALLOOR%2CEruvikulam%26Anamalais_in_the_background.jpg");
}
#page-content {
max-width: 50%;
}
<div id="header">
<div id="header-inner">
<div class="header-button menu-bars">
<a href="#">?</a>
</div>
<div id="header-link-1" class="header-button">
<a href="#" class="btn">Link 1</a>
</div>
<div id="header-link-2" class="header-button">
<a href="#" class="btn">Link 2</a>
</div>
<div id ="header-logos">
<a href="#"><img id="header-logo-bottom" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1000px-Google_%22G%22_Logo.svg.png"></a>
<a href="#"><img id="header-logo-top" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Google_Chrome_icon_%282011%29.svg/2000px-Google_Chrome_icon_%282011%29.svg.png"></a>
</div>
<div id="header-dates" class="header-button">
1 | 2 | 3 JAN 2018
</div>
<div id="header-socials" class="header-button">
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
</div>
<div class="header-button spacer">
</div>
</div>
</div>
<div id="landing-image" class="home-page"></div>
<div id="page-content">
LOREM IPSUM DOLOR SIT AMET, consectetur adipiscing elit. Nullam scelerisque magna non dui auctor placerat. Vestibulum cursus placerat mauris eget luctus. Maecenas sollicitudin mauris id erat porttitor, in dapibus ligula commodo. Donec sagittis sagittis felis non elementum. Nam facilisis non sapien non ultrices. Morbi cursus molestie nibh non tincidunt. Sed sagittis erat eu enim condimentum, ut lobortis nisi faucibus. Cras orci felis, molestie in ligula sit amet, vestibulum malesuada augue. Nullam id aliquam enim, eu vestibulum massa. Mauris ultricies ante sit amet leo ullamcorper, a lacinia nulla hendrerit. Aenean eros dolor, semper non nisi eu, maximus accumsan felis. Donec facilisis pellentesque lacus, quis vestibulum ipsum pretium tempus.
</div>
最佳答案
这不是立即发生的可见性转换,而是不透明度立即变为 0
。
在您的示例中 #header.expanded .header-button
具有 transition: visibility 0ms linear 300ms;
禁用为 .header-button< 声明的不透明度转换
.
为 #header.expanded .header-button
显式添加不透明度过渡应该可以解决问题。
var minHeaderHeight = 100; // Height of shrunken header, in pixels
var header = document.querySelector("#header"); // The header object
var maxHeaderHeight = outerHeight(header, true); // Height of expanded header, in pixels
document.addEventListener("DOMContentLoaded", initHeader);
function initHeader() {
var landingImage = document.getElementById("landing-image");
if (landingImage !== null) {
header.classList.add("expanded");
window.addEventListener('scroll', scrollCallback);
} else {
header.parentNode.style.paddingTop = minHeaderHeight + "px";
}
}
function scrollCallback() {
var scrollOffset = windowScrollTop();
var transitionEvent;
if (scrollOffset > 10) {
header.classList.remove("expanding");
header.classList.add("shrinking");
header.classList.remove("expanded");
} else {
header.classList.remove("shrinking");
header.classList.add("expanding");
header.classList.add("expanded");
}
}
// THESE TWO FUNCTIONS REPLICATE SIMILAR FUNCTIONS FROM JQUERY
function outerHeight(el, withMargins) {
withMargins = withMargins || false;
if (withMargins) {
var height = el.offsetHeight;
var style = getComputedStyle(el);
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
return height;
} else {
return el.offsetHeight;
}
}
function windowScrollTop(pos) {
if (typeof pos === 'undefined') {
if (window.pageYOffset !== undefined) {
return window.pageYOffset;
} else {
return (document.documentElement || document.body.parentNode || document.body).scrollTop;
}
} else {
document.documentElement.scrollTop = pos;
document.body.parentNode.scrollTop = pos;
document.body.scrollTop = pos;
window.pageYOffset = pos;
}
}
#header {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
justify-content: space-around;
align-items: center;
background-color: #000;
height: 100px;
text-transform: uppercase;
font-size: 2em;
color: white;
}
#header a {
color: white;
text-decoration: none;
}
#header-inner {
width: 100%;
z-index: 1;
display: flex;
justify-content: space-around;
align-items: center;
}
#header.expanded {
height: 100vh;
background-color: transparent;
}
#header.expanding {
-webkit-transition: height 300ms ease-in-out, background 300ms ease-in;
-moz-transition: height 300ms ease-in-out, background 300ms ease-in;
-ms-transition: height 300ms ease-in-out, background 300ms ease-in;
-o-transition: height 300ms ease-in-out, background 300ms ease-in;
transition: height 300ms ease-in-out, background 300ms ease-in;
}
#header.shrinking {
-webkit-transition: height 300ms ease-in-out, background 300ms ease-in;
-moz-transition: height 300ms ease-in-out, background 300ms ease-in;
-ms-transition: height 300ms ease-in-out, background 300ms ease-in;
-o-transition: height 300ms ease-in-out, background 300ms ease-in;
transition: height 300ms ease-in-out, background 300ms ease-in;
}
#header-logos {
position: relative;
}
#header-logos img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
max-height: 100px;
}
#header.shrinking img {
-webkit-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-moz-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-ms-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-o-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
}
#header.expanding img {
-webkit-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-moz-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-ms-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
-o-transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
transition: opacity 300ms ease-in-out, max-height 300ms ease-in-out;
}
.header-button {
-webkit-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-moz-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-ms-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
-o-transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
transition: opacity 300ms ease-in-out, visibility 0ms linear 0ms;
}
#header.expanded .header-button {
opacity: 0;
visibility: hidden;
-webkit-transition: opacity 300ms ease-in-out, visibility 0ms linear 300ms;
-moz-transition: opacity 300ms ease-in-out, visibility 0ms linear 300ms;
-ms-transition: opacity 300ms ease-in-out, visibility 0ms linear 300ms;
-o-transition: opacity 300ms ease-in-out, visibility 0ms linear 300ms;
transition: opacity 300ms ease-in-out, visibility 0ms linear 300ms;
}
#header-logo-top {
opacity: 0;
}
#header.expanded #header-logo-top {
opacity: 1;
}
#header.expanded img {
max-height: 500px;
}
#landing-image {
height: 100vh;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
#landing-image.home-page {
background-image: url("https://upload.wikimedia.org/wikipedia/commons/2/2f/KANTHALLOOR%2CEruvikulam%26Anamalais_in_the_background.jpg");
}
#page-content {
max-width: 50%;
}
<div id="header">
<div id="header-inner">
<div class="header-button menu-bars">
<a href="#">?</a>
</div>
<div id="header-link-1" class="header-button">
<a href="#" class="btn">Link 1</a>
</div>
<div id="header-link-2" class="header-button">
<a href="#" class="btn">Link 2</a>
</div>
<div id ="header-logos">
<a href="#"><img id="header-logo-bottom" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/Google_%22G%22_Logo.svg/1000px-Google_%22G%22_Logo.svg.png"></a>
<a href="#"><img id="header-logo-top" src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/e2/Google_Chrome_icon_%282011%29.svg/2000px-Google_Chrome_icon_%282011%29.svg.png"></a>
</div>
<div id="header-dates" class="header-button">
1 | 2 | 3 JAN 2018
</div>
<div id="header-socials" class="header-button">
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
<span>|</span>
<a href="#">?</a>
</div>
<div class="header-button spacer">
</div>
</div>
</div>
<div id="landing-image" class="home-page"></div>
<div id="page-content">
LOREM IPSUM DOLOR SIT AMET, consectetur adipiscing elit. Nullam scelerisque magna non dui auctor placerat. Vestibulum cursus placerat mauris eget luctus. Maecenas sollicitudin mauris id erat porttitor, in dapibus ligula commodo. Donec sagittis sagittis felis non elementum. Nam facilisis non sapien non ultrices. Morbi cursus molestie nibh non tincidunt. Sed sagittis erat eu enim condimentum, ut lobortis nisi faucibus. Cras orci felis, molestie in ligula sit amet, vestibulum malesuada augue. Nullam id aliquam enim, eu vestibulum massa. Mauris ultricies ante sit amet leo ullamcorper, a lacinia nulla hendrerit. Aenean eros dolor, semper non nisi eu, maximus accumsan felis. Donec facilisis pellentesque lacus, quis vestibulum ipsum pretium tempus.
</div>
关于javascript - 如何让可见性过渡延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47022441/
由于内容高度不同,我正在使用过渡最大高度而不是高度的技术,但我遇到了问题。 在增长或收缩的元素内,我有一个溢出的绝对定位元素,我想在父元素展开时显示该元素。 问题是如果我只在元素没有展开的时候设置ov
我正在用 CSS 制作一个表格,上面会有一些有趣的动画。单击文本字段时,它应该展开,但除此之外,它还应该使它旁边的按钮移动。谁能看到一个简单的方法来做到这一点?我在这里包含了代码: .inpu
我想在将鼠标悬停在按钮/div 标记上时仅使用 CSS3 过渡更改页面的背景颜色。我希望颜色逐渐出现,因此想使用过渡效果,但我不知道如何将页面的背景颜色与 div 上的悬停事件相关联。有人可以帮我处理
我这里有这个页面(进行中)http://kimwilddesigns.com/index_new.htm 在本节中,我希望能够将鼠标悬停在 li 上,使背景图像淡出并使 h2 淡入。这是否可以通过过渡
我的 CSS 有点问题。我正在看一本书学习 CSS3,我刚刚发现了 Transition 函数。所以我决定尝试一下,我想不出我错在哪里,希望你能帮助我。 这是我的 Index.html 文件
我正在尝试使使用 background-image 设置的背景图像随着页面变窄而淡出。我很确定它可以使用 CSS 转换来完成,但我对它们相当不熟悉。我想我想问的是,你能根据媒体查询将背景图片转换出来吗
有没有办法在 PyQt 中将过渡颜色作为背景?我尝试使用 CSS 的线性渐变,但不起作用 stylesheet = ("QWidget { background-color : linear-grad
我有这段代码,可以在一定的延迟后切换图像的不透明度: $(".pattern-overlay").css("background","black").delay(2000).queue(functio
我还在学习 jQuery,我现在想做的就是结合 html()带有过渡的方法(例如 hide() 和 show() ),以便更改具有过渡效果的 div 的 html。这是我尝试过的: $('div.co
我有一个链接列表和一些内容部分 ORANGE BLUE PINK GREEN gfgfgfgf gfgfgfgf gfgfgfgf gfgfgfgf 每个链接对应
我不想从 JS 触发 CSS 动画,而是相反。 如果我通过 -webkit-transition 或 transition: all 1000ms 类型的样式表做 CSS 动画,有没有办法在转换后触发
我想用节点的“宽度”制作动画。 在本例中,我的节点是“AnchorPane”。 我尝试在javafx中制作一个抽屉导航。 没有属性“width Property()”? new Key Value (
这是一个简单的设置,其中使用 left 属性将盒子向右移动。通过单击按钮更新该属性。为什么我第一次点击按钮时没有应用过渡动画? document.addEventListener('DOMConten
我是安卓开发的新手。我想创建一个带有两个 TextView 的启动画面。在此初始屏幕中,我想要两个转换 1) Text View 1 从顶部到中心的过渡2) text View 2 从底部到中心的过渡
我有三个 fragment ,F1、F2 和 F3。 在 F1 到 F2 转换并返回到 F1 的情况下,不会调用 F1 的 onCreateView()。 但在 F1 到 F3 转换并返回到 F1 的
我正在为我的应用程序使用扩展导航栏,将其高度增加 30 点。为此,我对 UINavigationBar 进行了子类化,这是我的 CustomNavigationBar.m: CGFloat Custo
我在下面创建了 jQuery 脚本,但是在将它转换为最好仅使用过渡的 CSS 时遇到了一些问题。如果有人可以帮助我,我会很高兴。 下面示例的解释: - 当你点击文本框时,一个空的 div 容器会掉下来
我有一个盒子,点击它会翻转。里面还有一张悬停时放大的图片,如图 fiddle 所示。 . 问题是当我将鼠标移出或放回时,隐藏的图像上的缩放过渡会短暂显示。 My attempt修复它: #box.fl
div 自己移动,我什至不想要也没有编写代码的移动。 这是我的问题: 我正在使用这样的 CSS 转换(想要移动背景图片): .mobile{ background: url(../img/galaxy
我知道如何进行淡入淡出的 CSS 过渡,但是否有解决方案可以从上到下淡出? 这是我的代码 .navbar-default{ -webkit-transition: all 0.5s ease;
我是一名优秀的程序员,十分优秀!