如何创建固定的浮动加号按钮? [英] How can I create a fixed floating plus button?
问题描述
我正在为我的移动应用程序创建一个浮动操作按钮.与Gmail和WhatsApp移动应用程序(请参见图中的红色按钮)中使用的类似.
I'm looking to create a floating action button for my mobile application. Similar to the ones used in the Gmail and WhatsApp mobile applications (see the red button in the image).
我正在使用jQuery Mobile构建一个小型应用程序,我希望该按钮可以将用户带到另一个页面.我已经研究了很长时间,但结果不一,但是主要的问题似乎是该按钮没有位于页面上所有其他内容的上方,并且一旦用户滚动,该按钮就不会固定在某个位置这一页.
I'm building a small app using jQuery Mobile and I would like the button to bring the user to another page. I've been researching for quite a while, with mixed results, but the main problem seems to be that the button doesn't sit above all of the other content on the page and doesn't stay fixed in a position once the user scrolls the page.
有人有什么资源或知识可以帮助您吗?谢谢
Does anyone have any resources or knowledge that could assist? Thank you
推荐答案
JQM footer
已经具有fixed
位置和正确的z-index
,可以与其他JQM小部件(如面板等)很好地配合使用.为什么不使用它?
The JQM footer
has already the fixed
positioning and the correct z-index
which plays nicely together with the other JQM widgets, like panels and so on. Why don't use that?
类ui-btn-left
和ui-btn-right
在footer
中的表现不佳,因此我使用的是透明背景的网格.这种方法的优点是,如果以后需要,可以快速添加更多按钮.
The classes ui-btn-left
and ui-btn-right
don't behaves well in footer
, so I am using a grid with transparent background. The advantage with this approach is that You can quickly add more buttons, if You need it later.
.ui-footer {
border-width: 0 !important;
background: transparent !important;
}
.ui-grid-d {
overflow: visible !important;
background: transparent !important;
}
.ui-grid-d > .ui-block-a,
.ui-grid-d > .ui-block-b,
.ui-grid-d > .ui-block-c,
.ui-grid-d > .ui-block-d,
.ui-grid-d > .ui-block-e {
text-align: center !important;
background: transparent !important;
padding-top: .3em;
padding-bottom: .9em;
}
.ui-icon-big {
height: 40px !important;
width: 40px !important;
margin-top: -18px !important;
border-radius: 20px !important;
}
.ui-icon-big:after {
width: 32px !important;
height: 32px !important;
background-size: 22px !important;
background-color: #F4123D !important;
background-color: rgba(244, 18, 61, 0.8) !important;
margin-top: -16px !important;
margin-left: -16px !important;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link href="https://fonts.googleapis.com/css?family=Jura" rel="stylesheet">
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
<link rel="stylesheet" href="style.css" />
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="script.js">
</script>
</head>
<body>
<div data-role="page" id="page-one">
<div data-role="content">
<h3>Page content</h3>
<hr>
</div>
<div data-role="footer" data-position="fixed" data-tap-toggle="false">
<div class="ui-grid-d">
<div class="ui-block-a"></div>
<div class="ui-block-b"></div>
<div class="ui-block-c"></div>
<div class="ui-block-d"></div>
<div class="ui-block-e">
<a href="#" class="ui-btn ui-corner-all ui-icon-plus ui-icon-big ui-btn-icon-notext"></a>
</div>
</div>
</div>
</div>
</body>
</html>
此外,当页面内容大于屏幕高度时,您可以决定不使用data-tap-toggle="false"
(默认值为true)以允许您的用户按需显示页脚按钮.
Moreover, You can decide to use data-tap-toggle="false"
on not (default is true) to allow Your users to show the footer buttons on demand, when the page content is bigger than the screen height.
这篇关于如何创建固定的浮动加号按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!