【问题标题】:animate div color plus hover animation动画 div 颜色加上悬停动画
【发布时间】:2018-06-29 05:06:00
【问题描述】:

我从 div 中创建了一条线,现在我要做的是为 div 颜色设置动画,背景为灰色,然后填充为白色,然后白色填充回灰色,就像它滑过一样。然后悬停在行和文本向上滑动约 10 像素,然后当释放它回到默认位置。

喜欢这个在底部example

.scroll-indicator {
    position: absolute;
    left: 50%;
    bottom: 0;
    z-index: 340;
    display: inline-block;
    width: 4.16667%;
    height: 6.66667%;
    min-height: 60px;
    font-family: 'rajdhani', 'Helvetica Neue', Helvetica, sans-serif;
    font-weight: bold;
    font-style: normal;
    color: #000;
    font-size: 16px;
}
.scroll-indicator .border-grey {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 100;
    width: 2px;
    height: 100%;
    background: #333;
}
.scroll-indicator .border {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 200;
    width: 2px;
    height: 100%;
    background: #000;
}
.scroll-indicator em {
    display: inline-block;
    font-style: normal;
    -webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
    -webkit-transform-origin: center center;
    transform-origin: center center;
    position: absolute;
    left: 0px;
    top: 12px;
}

@media screen and (max-width: 800px) {
.scroll-indicator {
    bottom: 0;
}
}
<a href="" class="scroll-indicator" style="opacity: 1; transform: matrix(1, 0, 0, 1, 0, 0);">
		<div class="border-grey"></div>
		<div class="border" style="transform: matrix(1, 0, 0, 1, 0, 0); transform-origin: 0% 0% 0px;"></div>
		<em>scroll</em>
	</a>

【问题讨论】:

  • 您能否提供一个指向 JSFiddle 的链接,以便对其进行正确测试和试验?此外,从这个问题中不清楚你的问题是什么。 S/O 不是要求完成工作的地方,而是回答您面临的特定问题的地方。请详细说明您能够完成的工作、您尝试过的工作、有效的工作、无效的工作等。
  • 上面的代码 sn-p 工作正常,只是没有线条动画

标签: css css-animations


【解决方案1】:

您可以使用 CSS3 animationstransitions 来实现该行为。

要实现动画,通常最好在尝试编码之前了解正在发生的事情。在这种情况下,我们可以通过 3 个简单的步骤来描述它:

  1. 元素以top: 0 开头,height: 0
  2. 元素留在top: 0height: 100%
  3. 元素移动到top: 100%height: 0

考虑到这一点,我们只需编码keyframe

以下是一个关于如何做到这一点的小例子:

body {
  background: #555;
}

.scroll-indicator {
	position: absolute;
	bottom: 0;
	width: 30px;
	left: 50%;
	height: 60px;
	transition: height .25s linear;
	cursor: pointer;
}

.scroll-indicator:hover {
	height: 75px;
}

.scroll-indicator .border-grey {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	width: 2px;
	background: #333;
}

.scroll-indicator .border-white {
	position: absolute;
	top: 0;
	left: 0;
	width: 2px;
	background: #fff;
	animation-name: animation;
    animation-duration: 3s;
	animation-iteration-count: infinite;
}

.scroll-indicator span {
	transform: rotate(-90deg);
	position: absolute;
	top: 10px;
  color: #fff;
}

@keyframes animation {
	0% {
		height: 0;
	}
	33% {
		top: 0;
		height: 100%;
	}
	66% {
		top: 100%;
		height: 0;
	}
	100% {}
}
<div class="scroll-indicator">
	<div class="border-grey"></div>
	<div class="border-white"></div>
	<span>scroll</span>
</div>

【讨论】:

  • 点击时它会上下跳跃以防止这种情况发生吗?
  • 你用的是什么浏览器?我确实注意到 Chrome 63 中的这种行为,但在 Firefox 和 Edge 中没问题。我猜这是 Chrome 的一个小问题。单击使元素以某种方式失去其悬停行为。
猜你喜欢
  • 2014-05-10
  • 1970-01-01
  • 1970-01-01
  • 2012-06-16
  • 1970-01-01
  • 2012-08-11
  • 2015-02-09
  • 1970-01-01
  • 2014-09-07
相关资源
最近更新 更多