- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我正在尝试模拟我在 Google 页面上看到的按钮转换 我已经尝试了各种方法来使转换平滑,但无法使其表现得像其 Google 对应部分那样平滑。具体来说,我想要#fade_one 的平滑扩展来填充#button 并平滑淡出。到目前为止,我还不能通过同时进行边距和宽度转换来实现这一点,它们各自的缓入和缓出参数的时间似乎不想同步移动。任何帮助将不胜感激!这是谷歌链接http://www.google.com/design/spec/animation/responsive-interaction.html#responsive-interaction-surface-response (向下滚动到“触摸时抬起”的位置),这是我的 fiddle 链接 http://jsfiddle.net/darth_business/hJchP/2/最后这是我的代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="button.css">
</head>
<body>
<div id="button">
<div id="fade_one"></div>
<p id="button_text">Click Me</p>
</div> <!-- button ends -->
#button {
height: 100px;
width: 200px;
background-color: #5677fc;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
#button:hover #fade_one {
width: 100%;
margin: 0 0 0 0;
opacity: 0;
}
#button_text {
color: #fff;
font-family: Roboto;
font-size: 50px;
}
#fade_one {
position: absolute;
height: 100px;
width: 0px;
margin: 0 0 0 100px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
background-color: #fff;
-moz-transition: width .5s ease-in-out, opacity 1s ease-in;, margin .25s ease-in-out, opacity 1s ease-in;
}
最后我想提一下,如果可以的话,我想尽可能地避免使用 java,谢谢!
最佳答案
您遇到的问题基本上与 CSS 定位有关。 #fade_one 元素具有绝对定位。当您给您一个元素绝对位置时,它会脱离页面的正常流并定位相对于其最近的定位祖先。
在您的情况下,您希望 #fade_one
元素覆盖在 #button
元素之上。换句话说,您希望 #fade_one
相对于 #button
定位。但是为了使绝对元素与其祖先相关,该祖先也需要“定位”。 #button
元素不在此处。
因此,当悬停被触发时,#fade_one
元素获得其定位祖先的 100% 宽度——这不是 #button
。在 fiddle 中,没有定位的祖先,所以它采用 body
元素的宽度。
诀窍是给你想要包含绝对定位子元素的祖先元素一个位置。在这里,只需给 #button
一个相对位置就足以将其更改为 #fade_one
的定位祖先。
这里是关于定位的更多信息:
https://developer.mozilla.org/en-US/docs/Web/CSS/position#Absolute_positioning
我还去掉了边距,因为它们是不必要的。试试这个 CSS:
#button {
height: 100px;
position: relative;
width: 200px;
background-color: #5677fc;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
}
#button:hover #fade_one {
width: 100%;
opacity: 0;
left: 0;
right: 0;
}
#button_text {
color: #fff;
font-family: Roboto;
font-size: 50px;
}
#fade_one {
position: absolute;
height: 100px;
width: 0px;
left: 100px;
top: 0;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
background-color: #fff;
transition: left .5s ease-in-out, width .5s ease-in-out, opacity 1s ease-in, opacity 1s ease-in;
}
在这里 fiddle :http://jsfiddle.net/hJchP/11/
关于html - 淡入淡出的按钮过渡不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24498166/
由于内容高度不同,我正在使用过渡最大高度而不是高度的技术,但我遇到了问题。 在增长或收缩的元素内,我有一个溢出的绝对定位元素,我想在父元素展开时显示该元素。 问题是如果我只在元素没有展开的时候设置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;
我是一名优秀的程序员,十分优秀!