答案 0 :(得分:14)
以下是一个关于如何使用css和html创建浮动操作按钮(没有悬停效果)的示例
<button class="kc_fab_main_btn">+</button>
.kc_fab_main_btn{
background-color:#F44336;
width:60px;
height:60px;
border-radius:100%;
background:#F44336;
border:none;
outline:none;
color:#FFF;
font-size:36px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
transition:.3s;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
.kc_fab_main_btn:focus {
transform:scale(1.1);
transform:rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
这是一个简单的浮动动作按钮jQuery插件,以防你需要它。但是它在点击触发器上使用而不是悬停。
答案 1 :(得分:5)
到目前为止,我已经找到了用于此目的的最佳教程:https://www.youtube.com/watch?v=iYFNaeEeCDI
有效的演示示例:https://verkkonet.com/downloads/demo.php?id=c9
HTML:
<div class="fab-container">
<div class="fab fab-icon-holder">
<i class="fas fa-question"></i>
</div>
<ul class="fab-options">
<li>
<span class="fab-label">Documentation</span>
<div class="fab-icon-holder">
<i class="fas fa-file-alt"></i>
</div>
</li>
<li>
<span class="fab-label">Video Tutorials</span>
<div class="fab-icon-holder">
<i class="fas fa-video"></i>
</div>
</li>
<li>
<span class="fab-label">Live Chat</span>
<div class="fab-icon-holder">
<i class="fas fa-comments"></i>
</div>
</li>
<li>
<span class="fab-label">Feedback</span>
<div class="fab-icon-holder">
<i class="fas fa-comment-alt"></i>
</div>
</li>
</ul>
</div>
CSS:
.fab-container {
position: fixed;
bottom: 50px;
right: 50px;
z-index: 999;
cursor: pointer;
}
.fab-icon-holder {
width: 50px;
height: 50px;
border-radius: 100%;
background: #016fb9;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.fab-icon-holder:hover {
opacity: 0.8;
}
.fab-icon-holder i {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
font-size: 25px;
color: #ffffff;
}
.fab {
width: 60px;
height: 60px;
background: #d23f31;
}
.fab-options {
list-style-type: none;
margin: 0;
position: absolute;
bottom: 70px;
right: 0;
opacity: 0;
transition: all 0.3s ease;
transform: scale(0);
transform-origin: 85% bottom;
}
.fab:hover+.fab-options,
.fab-options:hover {
opacity: 1;
transform: scale(1);
}
.fab-options li {
display: flex;
justify-content: flex-end;
padding: 5px;
}
.fab-label {
padding: 2px 5px;
align-self: center;
user-select: none;
white-space: nowrap;
border-radius: 3px;
font-size: 16px;
background: #666666;
color: #ffffff;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
margin-right: 10px;
}
整个示例来自:https://verkkonet.com/。 youtube视频教程非常适合学习如何执行此操作。
答案 2 :(得分:3)
这是我尝试悬停时的浮动按钮(HTML 和 CSS)的示例代码。
.flBtnCntr {
display: inline-flex;
position: absolute;
top: 50px;
left: 50px
}
.flBtnBox {
outline: 0;
border: 0;
border-radius: 50%;
background-color: #2978d3;
color: #fff;
cursor: pointer
}
.flBtnBox.big {
background-color: #2978d3;
font-size: 30px;
height: 50px;
width: 50px
}
.flBtnBox.small {
animation: showBtn 150ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
transform: scale(0);
background-color: #363636;
margin: 0 5px;
font-size: 20px;
height: 30px;
width: 30px;
}
.flBtnBox.small:nth-child(2) {
animation-delay: 150ms
}
.flBtnBox.small:nth-child(3) {
animation-delay: 300ms
}
@keyframes showBtn {
0% {
transform: scale(0)
}
100% {
transform: scale(1)
}
}
.flBtnBox.big:hover {
box-shadow: 0 0 10px rgba(41,120,211,0.4)
}
.flBtnBox.small:hover {
box-shadow: 0 0 10px rgba(0,0,0,0.3)
}
.flBtns {
position: absolute;
left: 100%;
top: 0;
bottom: 0;
display: none;
padding: 0 5px;
align-items: center
}
.flBtnCntr:hover .flBtns {
display: inline-flex
}
<div class="flBtnCntr">
<button class="flBtnBox big">+</button>
<div class="flBtns">
<button class="flBtnBox small">+</button>
<button class="flBtnBox small">+</button>
<button class="flBtnBox small">+</button>
</div>
</div>
代码笔链接: Demo
答案 3 :(得分:3)
我今天重新审视了我的解决方案,并对我昨天未完成的那些部分添加了最后的润色。我还添加了一些额外的增强和风格改进。现在,对于 #mega-button
父级,它使用渐变背景,然后通过使用超大渐变和过渡 background-position
属性平滑过渡到褪色的蓝灰色背景颜色。当我旋转并增加子 .sub-button
元素的大小时,我还在悬停时减小此按钮的大小,以呈现从 .sub-button
后面滚出的 #mega-button
元素的外观。
为了让过渡感觉更平滑和自然,我还在每个 transition-delay
元素之间添加了一个轻微的 .sub-button
以创建瀑布效果,而不是它们都在彼此之上滚动。我在我的 SCSS 中使用 for 循环实现了这一点以及每个 .sub-button
的独特位置,并反向迭代 transition-delay
以使最右侧的按钮首先动画化。
当按钮从后面滚出时,我还使用了一些玻璃化样式,使 #mega-button
看起来像磨砂玻璃一样:backdrop-filter: blur(4px)
当您单击任何子按钮时,它们会通过 :target
触发其关联的模态。模态本身都提供了几种纯 HTML/CSS 方式来关闭模态:
每个模态都是完全独特的,并由其关联的 .sub-button
触发。我还在模态样式背后构建了一些系统,其中包含 .modal-content
、.modal-header
和 .modal-body
的全局样式,以及 .modal-close
的上下文样式类,当插入到模态的主元素中时,它显示为模态后面的可点击/可取消背景,而当包含在 .modal-content
元素中时,它在右上角显示为“x”。单击任一将关闭模态。
我今天添加的最后两个好东西:
#mega-button
上方的悬停工具提示。此工具提示无法单击,并且不会在功能上阻碍其后面的任何内容,因为它的 pointer-events
属性设置为 none
。当鼠标悬停在 opacity: 0
或其任何后代上时,或者当模态打开时,通过通用同级组合器 (#mega-button
),它会淡化为 ~
。这是成品:
@charset "UTF-8";
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap");
.modal .modal-content .modal-body {
-ms-overflow-style: none;
scrollbar-width: none;
}
.modal .modal-content .modal-body::-webkit-scrollbar {
display: none;
}
body {
margin: 0;
background-color: #eceff1;
font-family: "Poppins", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.warning {
display: block !important;
padding: 12px 15px !important;
background-color: rgba(244, 67, 54, 0.25) !important;
border-radius: 8px !important;
font-weight: 500 !important;
color: #e53935 !important;
text-align: left !important;
}
.warning > i {
position: relative;
top: 1px;
margin-right: 8px;
transform: scale(1.25);
}
#mega-button {
display: flex;
align-items: center;
justify-content: center;
position: fixed;
bottom: 15px;
left: 15px;
width: 50px;
height: 50px;
cursor: default;
transition: all 0.15s ease-out;
z-index: 1;
will-change: width;
}
#mega-button > .tooltip {
padding: 5px 10px;
position: absolute;
left: 10px;
top: -9px;
transform: translateY(-100%);
white-space: nowrap;
background-color: #fff;
border-radius: 8px;
filter: drop-shadow(0 2px 2px rgba(120, 144, 156, 0.5));
box-shadow: inset 0 0 0 1px rgba(120, 144, 156, 0.1);
font-weight: 500;
color: #1e4989;
-webkit-animation: tooltip-hover;
animation: tooltip-hover;
/* @keyframes duration | easing-function | delay |
iteration-count | direction | fill-mode | play-state | name */
-webkit-animation: 1s ease-in-out 0s infinite alternate both tooltip-hover;
animation: 1s ease-in-out 0s infinite alternate both tooltip-hover;
transition: all 0.15s ease-out;
pointer-events: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
will-change: opacity;
}
#mega-button > .tooltip::before {
content: "";
display: block;
position: absolute;
bottom: 1px;
left: 8px;
width: 12px;
height: 6px;
background-color: inherit;
-webkit-clip-path: polygon(0 0, 100% 0, 50% 100%);
clip-path: polygon(0 0, 100% 0, 50% 100%);
transform: translateY(100%);
}
#mega-button::before {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
left: 0;
top: 0;
width: 50px;
height: 50px;
padding-top: 4px;
background: 100% 100%/250% 100% #fff linear-gradient(135deg, transparent 33%, #2c92c8 66%, #892cc8) no-repeat;
border-radius: 50%;
content: "";
font-family: "Font Awesome 5 Pro";
font-size: 32px;
font-weight: 400;
color: #fff;
transition: inherit;
box-sizing: border-box;
cursor: inherit;
box-shadow: 0 10px 20px -10px #1a237e;
backdrop-filter: blur(4px);
-webkit-backdrop-filter: blur(4px);
will-change: transform, background-color, box-shadow;
}
#mega-button > .sub-button {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 50%;
left: 25px;
width: 36px;
height: 36px;
background: #2c92c8;
border-radius: 50%;
text-decoration: none !important;
box-shadow: 0 10px 20px -10px #1a237e;
transform: translate(-50%, -50%) scale(0.75);
transition: inherit;
z-index: -1;
will-change: transform, transition-duration;
}
#mega-button > .sub-button::before {
font-family: "Font Awesome 5 Pro";
color: #fff;
font-size: 20px;
font-weight: 400;
transform: rotate(-90deg);
transition: inherit;
will-change: transform;
}
#mega-button > .sub-button#buttons--write::before {
content: "";
}
#mega-button > .sub-button#buttons--archive::before {
content: "";
}
#mega-button > .sub-button#buttons--delete::before {
content: "";
}
#mega-button:hover {
width: calc(50px + 2px + 123px);
}
#mega-button:hover::before {
transform: rotate(45deg) scale(0.675);
padding-right: 2px;
box-shadow: 7.5px 7.5px 20px -10px rgba(55, 71, 79, 0);
background: -100% 100%/250% 100% rgba(144, 164, 174, 0.625) linear-gradient(135deg, transparent 33%, #2c92c8 66%, #892cc8) no-repeat;
}
#mega-button:hover::after {
width: 200px;
}
#mega-button:hover > .sub-button::before {
transform: rotate(0deg);
}
#mega-button:hover > .sub-button:nth-of-type(1) {
transform: translate(calc(-50% + 50px + 0% + 0px + 2px), -50%) scale(1);
transition-delay: 0.1s;
}
#mega-button:hover > .sub-button:nth-of-type(1):hover {
transform: translate(calc(-50% + 50px + 0% + 0px + 2px), -50%) scale(1.18);
transition-duration: 0.15s;
}
#mega-button:hover > .sub-button:nth-of-type(2) {
transform: translate(calc(-50% + 50px + 100% + 5px + 2px), -50%) scale(1);
transition-delay: 0.05s;
}
#mega-button:hover > .sub-button:nth-of-type(2):hover {
transform: translate(calc(-50% + 50px + 100% + 5px + 2px), -50%) scale(1.18);
transition-duration: 0.15s;
}
#mega-button:hover > .sub-button:nth-of-type(3) {
transform: translate(calc(-50% + 50px + 200% + 10px + 2px), -50%) scale(1);
transition-delay: 0s;
}
#mega-button:hover > .sub-button:nth-of-type(3):hover {
transform: translate(calc(-50% + 50px + 200% + 10px + 2px), -50%) scale(1.18);
transition-duration: 0.15s;
}
#mega-button:hover > .sub-button:hover {
background-color: #3949ab;
}
#mega-button:hover > .sub-button:hover::before {
transform: scale(0.85);
}
#mega-button:hover .tooltip, .modal:target ~ #mega-button .tooltip {
opacity: 0;
}
.modal {
display: none;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: transparent;
z-index: 2;
}
.modal > .modal-close::before {
content: "";
display: block;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
background-color: rgba(38, 50, 56, 0.5);
}
.modal .modal-content {
display: flex;
flex-direction: column;
position: fixed;
left: 50%;
top: 50%;
width: 90%;
max-width: 600px;
max-height: 90%;
overflow: visible;
transform: translate(-50%, -50%);
}
.modal .modal-content > div:first-of-type {
border-top-left-radius: 15px;
border-top-right-radius: 15px;
}
.modal .modal-content > div:last-of-type {
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
}
.modal .modal-content > .modal-close::after {
content: "";
display: flex;
align-items: center;
justify-content: center;
position: absolute;
right: 0;
top: 0;
width: 28px;
height: 28px;
z-index: -1;
background-color: #546e7a;
border-radius: 50%;
font-family: "Font Awesome 5 Pro";
font-size: 18px;
font-weight: 400;
color: #fff;
transform: translate(37.5%, -37.5%);
transition: all 0.15s ease-out;
z-index: 1;
}
.modal .modal-content > .modal-close ~ div:first-of-type {
border-top-right-radius: 0;
}
.modal .modal-content > .modal-close:hover::after {
background-color: #263238;
}
.modal .modal-content .modal-header {
padding: 10px 5px;
background-color: #37474f;
font-size: 16px;
font-weight: 600;
color: #fff;
text-transform: uppercase;
letter-spacing: 2px;
text-align: center;
}
.modal .modal-content .modal-body {
flex: 1;
display: flex;
flex-direction: column;
padding: 15px;
overflow-y: auto;
background-color: #eceff1;
}
.modal .modal-content .modal-body p {
color: #455a64;
text-align: center;
}
.modal .modal-content .modal-body p + p, .modal .modal-content .modal-body p + .modal-actions {
margin-top: 0;
}
.modal .modal-content .modal-body > :first-child {
margin-top: 0;
}
.modal .modal-content .modal-body label {
margin-bottom: 4px;
font-weight: 500;
color: #78909c;
}
.modal .modal-content .modal-body label:not(:first-of-type) {
margin-top: 10px;
}
.modal .modal-content .modal-body input, .modal .modal-content .modal-body textarea {
font-family: inherit;
}
.modal .modal-content .modal-body input:focus, .modal .modal-content .modal-body textarea:focus {
outline: 0 !important;
}
.modal .modal-content .modal-body input {
display: block;
width: 235px;
padding: 4px 10px;
align-self: flex-start;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background-color: #303f9f;
border: none;
border-radius: 10px;
font-size: 16px;
font-weight: 400;
line-height: 26px;
color: #455a64;
box-sizing: border-box;
cursor: pointer;
transition: all 0.15s ease-out;
will-change: width, padding, background-color, border-radius, font-size, font-weight;
}
.modal .modal-content .modal-body input::-webkit-input-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-size: inherit;
font-weight: 500;
color: #fff;
-webkit-transition: inherit;
transition: inherit;
will-change: font-size, font-weight, color;
}
.modal .modal-content .modal-body input:-moz-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-size: inherit;
font-weight: 500;
color: #fff;
-moz-transition: inherit;
transition: inherit;
will-change: font-size, font-weight, color;
}
.modal .modal-content .modal-body input::-moz-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-size: inherit;
font-weight: 500;
color: #fff;
-moz-transition: inherit;
transition: inherit;
will-change: font-size, font-weight, color;
}
.modal .modal-content .modal-body input:-ms-input-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-size: inherit;
font-weight: 500;
color: #fff;
-ms-transition: inherit;
transition: inherit;
will-change: font-size, font-weight, color;
}
.modal .modal-content .modal-body input:focus, .modal .modal-content .modal-body input:valid {
width: 100%;
padding: 4px 0;
background-color: transparent;
border-radius: 0;
cursor: text;
}
.modal .modal-content .modal-body input:focus::-webkit-input-placeholder, .modal .modal-content .modal-body input:valid::-webkit-input-placeholder {
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body input:focus:-moz-placeholder, .modal .modal-content .modal-body input:valid:-moz-placeholder {
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body input:focus::-moz-placeholder, .modal .modal-content .modal-body input:valid::-moz-placeholder {
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body input:focus:-ms-input-placeholder, .modal .modal-content .modal-body input:valid:-ms-input-placeholder {
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body input:valid:not(:focus) {
font-size: 20px;
font-weight: 500;
}
.modal .modal-content .modal-body textarea {
display: block;
min-height: 150px;
padding: 8px 10px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
resize: vertical;
background-color: #fff;
border: none;
border-radius: 10px;
box-shadow: 0 5px 10px -5px #37474f;
font-size: 16px;
font-weight: 400;
line-height: 18px;
color: #455a64;
box-sizing: border-box;
}
.modal .modal-content .modal-body textarea::-webkit-input-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body textarea:-moz-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body textarea::-moz-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body textarea:-ms-input-placeholder {
font-family: "Font Awesome 5 Pro", "Poppins", sans-serif;
font-weight: inherit;
color: #78909c;
}
.modal .modal-content .modal-body .modal-actions {
display: flex;
align-items: center;
justify-content: center;
margin-top: 20px;
}
.modal .modal-content .modal-body .modal-actions a, .modal .modal-content .modal-body .modal-actions button {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
display: inline-flex;
align-items: center;
justify-content: center;
height: 40px;
padding: 0 15px;
background-color: #607d8b;
border: none;
border-radius: 20px;
box-shadow: 0 5px 10px -15px #455a64;
font-family: inherit;
font-size: 16px;
font-weight: 500;
color: #fff;
text-decoration: none !important;
transition: box-shadow 0.15s ease-out;
will-change: box-shadow;
cursor: pointer;
}
.modal .modal-content .modal-body .modal-actions a.write, .modal .modal-content .modal-body .modal-actions button.write {
background-color: #2196f3;
}
.modal .modal-content .modal-body .modal-actions a.archive, .modal .modal-content .modal-body .modal-actions button.archive {
background-color: #ef6c00;
}
.modal .modal-content .modal-body .modal-actions a.delete, .modal .modal-content .modal-body .modal-actions button.delete {
background-color: #f44336;
}
.modal .modal-content .modal-body .modal-actions a.write, .modal .modal-content .modal-body .modal-actions button.write {
box-shadow: 0 5px 10px -15px #0d47a1;
}
.modal .modal-content .modal-body .modal-actions a.archive, .modal .modal-content .modal-body .modal-actions button.archive {
box-shadow: 0 5px 10px -15px #bf360c;
}
.modal .modal-content .modal-body .modal-actions a.delete, .modal .modal-content .modal-body .modal-actions button.delete {
box-shadow: 0 5px 10px -15px #b71c1c;
}
.modal .modal-content .modal-body .modal-actions a:hover, .modal .modal-content .modal-body .modal-actions button:hover {
box-shadow: 0 5px 10px -5px #455a64;
}
.modal .modal-content .modal-body .modal-actions a:hover.write, .modal .modal-content .modal-body .modal-actions button:hover.write {
box-shadow: 0 5px 10px -5px #0d47a1;
}
.modal .modal-content .modal-body .modal-actions a:hover.archive, .modal .modal-content .modal-body .modal-actions button:hover.archive {
box-shadow: 0 5px 10px -5px #bf360c;
}
.modal .modal-content .modal-body .modal-actions a:hover.delete, .modal .modal-content .modal-body .modal-actions button:hover.delete {
box-shadow: 0 5px 10px -5px #b71c1c;
}
.modal .modal-content .modal-body .modal-actions a + a, .modal .modal-content .modal-body .modal-actions a + button, .modal .modal-content .modal-body .modal-actions button + a, .modal .modal-content .modal-body .modal-actions button + button {
margin-left: 4px;
}
.modal:target {
display: block;
}
@-webkit-keyframes tooltip-hover {
from {
transform: translateY(-100%);
}
to {
transform: translateY(calc(-100% - 5px));
}
}
@keyframes tooltip-hover {
from {
transform: translateY(-100%);
}
to {
transform: translateY(calc(-100% - 5px));
}
}
<script src="https://kit.fontawesome.com/07afc061fe.js" crossorigin="anonymous"></script>
<div id="modal-write" class="modal">
<a href="#" class="modal-close"></a>
<div class="modal-content">
<a href="#" class="modal-close"></a>
<div class="modal-header">New Post</div>
<div class="modal-body">
<label for="modal-write-title">Post Title</label>
<input type="text" name="title" id="modal-write-title" placeholder=" Give your post a name..." required>
<label for="modal-write-body">Post Body</label>
<textarea name="body" cols="30" rows="10" id="modal-write-body" placeholder="What would you like to say?" required></textarea>
<div class="modal-actions">
<a href="#">Cancel</a>
<button class="write">Post</button>
</div>
</div>
</div>
</div>
<div id="modal-archive" class="modal">
<a href="#" class="modal-close"></a>
<div class="modal-content">
<a href="#" class="modal-close"></a>
<div class="modal-header">Archive Post</div>
<div class="modal-body">
<p>Would you like to archive your post?</p>
<div class="modal-actions">
<a href="#">Cancel</a>
<button class="archive">Archive</button>
</div>
</div>
</div>
</div>
<div id="modal-delete" class="modal">
<a href="#" class="modal-close"></a>
<div class="modal-content">
<a href="#" class="modal-close"></a>
<div class="modal-header">Delete Post</div>
<div class="modal-body">
<p>Are you sure you want to delete your post?</p>
<p class="warning"><i class="far fa-exclamation-circle"></i>This cannot be undone.</p>
<div class="modal-actions">
<a href="#">Cancel</a>
<button class="delete">Delete</button>
</div>
</div>
</div>
</div>
<div id="mega-button">
<div class="tooltip">Hover me!</div>
<a class="sub-button" id="buttons--write" href="#modal-write"></a>
<a class="sub-button" id="buttons--archive" href="#modal-archive"></a>
<a class="sub-button" id="buttons--delete" href="#modal-delete"></a>
</div>
以下是此解决方案的完整 CodePen,其所有原始的“Sass”-y 荣耀:https://codepen.io/brandonmcconnell/pen/082f4ee58d234501757b8d6a748c514b?editors=0100
如果您希望在最终的 CSS 中保持所有这些计算动态,那么这个 SCSS 中的所有动态变量都可以简单地转换为 CSS 自定义属性。
答案 4 :(得分:2)
您是否预先编写了任何代码,或者您只是在寻求教程?
如果是前者,这里有一些关于如何构建代码以使其工作的想法:
var el = $('a.button'); // the element you want to hover over
var hi = $('div.hidden'); // the div containing the hidden buttons
el.hover(function(){
//do this when the mouse hovers over the link, eg
hi.show('slide',{direction:'right'},250);
}, function(){
//do this when the mouse leaves the link, eg
hi.hide('slide',{direction:'left'},250);
});
答案 5 :(得分:1)
:target
使用模态实现具有来自 this answer 的一些样式的模态实现
.fab-container {
position: fixed;
bottom: 20px;
left: 20px;
z-index: 999;
cursor: pointer;
}
.fab-icon-holder {
width: 50px;
height: 50px;
border-radius: 100%;
background: black;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.fab-icon-holder:hover {
opacity: 0.8;
}
.fab-icon-holder i {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
font-size: 25px;
color: #ffffff;
}
.fab {
width: 60px;
height: 60px;
background: #3F51B5;
}
.fab-options {
list-style-type: none;
margin: 0;
position: absolute;
bottom: 0px;
left: 30px;
opacity: 0;
transition: all 0.3s ease;
transform: scale(0);
transform-origin: 85% left;
}
.fab:hover+.fab-options,
.fab-options:hover {
opacity: 1;
transform: scale(1);
}
.fab-options li {
display: flex;
justify-content: flex-end;
padding: 5px;
}
:target {
visibility: visible !important;
}
#modal {
visibility: hidden;
width: 80%;
height: 80%;
position: fixed;
left: 10%;
box-shadow: 0 0 3px black;
}
#modal .content {
margin: 1em;
}
#modal #close {
position: absolute;
top: 10px;
right: 15px;
font-size: 2em;
cursor: pointer;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="fab-container">
<div class="fab fab-icon-holder">
<i class="fas fa-question material-icons">add</i>
</div>
<ul class="fab-options">
<li>
<div class="fab-icon-holder">
<a href="#modal" style="all:unset"><i class="fas fa-file-alt material-icons">launch</i></a>
</div>
</li>
</ul>
</div>
<div id="modal">
<div class="content">
This is a modal
</div>
<a href="#"><i id="close">×</i></a>
</div>
这是我的旧的(虽然样式很差):
html,
body {
height: 100%;
}
.buttons {
position: fixed;
bottom: 10px;
left: 10px;
display: flex;
align-items: center;
}
.button {
border-radius: 50%;
width: 25px;
height: 25px;
cursor: pointer;
transition: 1s;
}
.button {
color: white;
}
.parent-button {
box-shadow:0 0 3px #3F51B5;
background-color: #3F51B5;
padding: 1em;
color: white;
}
.child-button {
box-shadow:0 0 3px black;
background-color: black;
margin-left: 5px;
padding:0.75em;
opacity:0;
}
.child-button a{
color:white;
}
.parent-button:hover~.child-button{
opacity:1;
}
.child-button:hover{
opacity:1;
}
:target {
visibility: visible !important;
}
#modal {
visibility: hidden;
width: 80%;
height: 80%;
position: fixed;
left: 10%;
box-shadow: 0 0 3px black;
}
#modal .content {
margin: 1em;
}
#modal #close {
position: absolute;
top: 10px;
right: 15px;
font-size: 2em;
cursor: pointer;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="buttons">
<div class="parent-button button">
<i class="material-icons">add</i>
</div>
<div class="child-button button">
<a href="#modal"><i class="material-icons">fullscreen</i></a>
</div>
</div>
<div id="modal">
<div class="content">
This is a modal
</div>
<a href="#"><i id="close">×</i></a>
</div>
答案 6 :(得分:0)
这是我对这个问题的回答。
预览: https://jsfiddle.net/rp0jg576/53/
HTML 和 CSS 代码:
i {
color: #fff;
font-size: 20px !important;
/* 24px preferred icon size */
}
a {
text-decoration: none;
}
#btn {
display: none;
}
.button-parent {
display: flex;
}
.button {
width: 50px;
height: 50px;
display: block;
margin: 5px;
background-color: #3498db;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
/* link and link-parent */
.link-parent {
display: none;
justify-content: center;
align-items: center;
transition: all .3s;
}
.link-item {
background-color: #2c3e50;
display: block;
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 5px;
transform: translateY(5px);
display: flex;
justify-content: center;
align-items: center;
animation-name: move-up;
animation-duration: .3s;
animation-timing-function: ease-in;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
/* control click */
#btn:checked~.link-parent {
display: flex;
}
/* animation */
@keyframes move-up {
0% {
transform: translateY(5px);
}
33% {
transform: translateY(0px);
}
66% {
transform: translateY(-5px);
}
100% {
transform: translateY(0px);
}
}
#link-one {
animation-delay: .1s;
}
#link-two {
animation-delay: .2s;
}
#link-third {
animation-delay: .3s;
}
#link-forth {
animation-delay: .4s;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class='button-parent'>
<input type="checkbox" id='btn'>
<label for="btn" class='button'>
<i class="material-icons">close</i>
</label>
<div class="link-parent">
<a href='#' class='link-item' id='link-one'>
<i class="material-icons">home</i>
</a>
<a href='#' class='link-item' id='link-two'>
<i class="material-icons">article</i>
</a>
<a href='#' class='link-item' id='link-third'>
<i class="material-icons">settings</i>
</a>
<a href='#' class='link-item' id='link-forth'>
<i class="material-icons">room</i>
</a>
</div>
</div>
答案 7 :(得分:0)
类型 1:宽度从 struct ContentView: View {
@State var doIWantThisViewToShow: Bool = false
var body: some View {
VStack {
Button("Show/Hide MyView") {
doIWantThisViewToShow.toggle()
}
if doIWantThisViewToShow {
MyView()
.padding()
}
}
}
}
调整为适合内容的宽度。
0px
.material-icons {
vertical-align: middle;
user-select: none;
}
.action-container {
position: fixed;
bottom: 10px;
left: 10px;
display: flex;
cursor: pointer;
}
.child-container {
display: flex;
width: 0px;
transition: 1s;
overflow: hidden;
}
.action-btn {
width: fit-content;
border-radius: 50%;
display: inline-block;
}
.action-parent {
padding: 1em;
background-color: #3F51B5;
color: white;
}
.action-parent:hover+.child-container {
width: 159px;
}
.action-child {
padding: 0.75em;
background-color: black;
color: white;
height: fit-content;
margin-top: 5px;
margin-left: 5px;
}
.child-container:hover {
width: 159px;
}
类型 2:整个子操作按钮容器正在滑入:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="action-container">
<div class="action-parent action-btn">
<i class="material-icons">add</i>
</div>
<div class="child-container">
<div class="action-child action-btn">
<i class="material-icons">add</i>
</div>
<div class="action-child action-btn">
<i class="material-icons">add</i>
</div>
<div class="action-child action-btn">
<i class="material-icons">add</i>
</div>
</div>
</div>
.material-icons {
vertical-align: middle;
user-select: none;
}
.action-container {
position: fixed;
bottom: 10px;
left: 10px;
display: flex;
cursor: pointer;
}
.child-container {
display: flex;
}
.action-btn {
width: fit-content;
border-radius: 50%;
display: inline-block;
}
.action-parent {
padding: 1em;
background-color: #3F51B5;
color: white;
z-index: 1;
}
.action-parent:hover+.child-container .action-child {
margin-left: 5px;
}
.action-child {
transition: 1s;
padding: 0.75em;
background-color: black;
color: white;
height: fit-content;
margin-top: 5px;
margin-left: -50px;
}