Coder Social home page Coder Social logo

nobitagit / material-floating-button Goto Github PK

View Code? Open in Web Editor NEW
297.0 15.0 74.0 206 KB

Vanilla Js Material design floating menu with action buttons.

Home Page: http://nobitagit.github.io/material-floating-button/

License: MIT License

JavaScript 100.00%

material-floating-button's Introduction

Material Floating Button

Material design floating button action implementation.

Made to be semantic, fast and easy to customize. Shamelessly inspired by action buttons from Google Inbox, Evernote and Path.

See a demo here to see it in action or just take a look at this awesome gif:

Test all the available effects to date in the demo.

##Other versions## Also available as:

##How to use## ###Basic usage### Clone/download the repo from Github or just use npm:

npm install mfb --save

(Optionally) run npm install to have access to the configured Grunt tasks if you use them, then reference the basic css styles in your <head> like so:

<link href="path/to/css/mfb.css" rel="stylesheet">

Use the appropriate html structure (better explained later), for example:

<ul class="mfb-component--tl mfb-slidein" data-mfb-hover>
  <!-- the menu content -->
</ul>

Everything should already work fine.

You may or may not want to include the provided mfb.js script depending on the need to support click/touch.

<script src="path/to/js/mfb.js"></script>

For a breakdown on why and when you need to include the script please refer to Toggling options and touch devices support.

###Customising the component### ####HTML#### The basic structure of the component is the following (the customisable classes/attributes are in curly braces):

<ul class="{{placement-class}} {{effect-class}}" {{hover/click-to-open}} {{menu-state}}>
  <li class="mfb-component__wrap">
    <!-- the main menu button -->
    <a data-mfb-label="{{the label text of the main button}}" class="mfb-component__button--main">
      <!-- the main button icon visibile by default -->
      <i class="mfb-component__main-icon--resting {{icon-class}}"></i>
      <!-- the main button icon visibile when the user is hovering/interacting with the menu -->
      <i class="mfb-component__main-icon--active {{active-icon-class}}"></i>
    </a>
    <ul class="mfb-component__list">
      <!-- a child button, repeat as many times as needed -->
      <li>
        <a href="link.html" data-mfb-label="{{the label text of the a child button}}" class="mfb-component__button--child">
          <i class="mfb-component__child-icon {{icon-class}}"></i>
        </a>
      </li>
    </ul>
  </li>
</ul>

####SCSS/CSS####

Although you can use the provided css as is, it's highly likely that you will want to customise the looks and behavior of the component by changing its underlying css. A number of variables is provided for your convenience in the SASS file.

The best way to tweak them is leave the src/mfb.scss source as is, import it in your own style sheet and define your custom variables before the @import statement right there. For example:

// your .scss working file
$main-color: #4991EF;

@import "path/to/src/mfb.scss";

This will leave the core files unchanged from the source. You will then be able to keep this repo as upstream and pull in any future changes without having to worry about overwriting your changes.

Here below is a breakdown of all the variables currently available, along with their defaults.

#####Basic#####

Variable name Default value Explanation
$main-color #E40A5D main/primary color of the component
$bright-text rgba(255, 255, 255, 0.8) color of icons and text
$number-of-child-buttons 4 how many child buttons the component supports

#####Effects##### n.b. - set to true to include the effect styles in the compiled .css file. To actually activate the desired effect you need to reference the corresponding class in the markup (see here)

Variable name Default value
$effects-zoomin true
$effects-slidein true
$effects-slidein-spring true
$effects-fountain true

As a suggestion, try to only include the animation you're using in production in order to have a much lighter css.

#####Speeds#####

Variable name Default value Explanation
$delay-staggering-inflate 0.1s each child button can appear with a slight, more natural delay (set to 0 for no-delay)
$slide-speed 0.5s the child buttons animate at this speed
$label-hover-off 0.5s the child buttons labels fade in at this speed
$label-hover-on 0.3s the child buttons labels fade out at this speed

#####Sizes#####

Variable name Default value Explanation
$main_button_size 25px the distance of the main button from the closest corners of the screen
$labels-font-size 13px font-size for all labels
$labels-padding-vertical 4px top & bottom padding for the labels
$labels-padding-horizontal 10px left & right padding for the labels

You can compile the final css on your own or use the provided, pre-configured Grunt tasks for it. After installing all dependencies (by running npm install from the terminal) type grunt sass (on time compilation) or grunt watch-css (live reload triggered after the scss files are changed).

####Toggling options and touch devices support#### The menu can be customised to be activated either on hover or on click/tap. To assign the desired toggling method the component provides some attributes to add this functionality in a declarative way right from the markup.

#####Hover toggling#####

If you're only interested in desktop support and want the menu to be activated on hover you won't need to include any scripts as that animation is CSS-based and included in the stylesheet provided. Just set the data-mfb-toggle attribute to hover like so:

<ul class="mfb-component--tl mfb-slidein" data-mfb-toggle="hover">

#####Click toggling#####

To add click and touch support (and to support the open/close animation programmatically, more on this later) include the mfb.js file and reference it in the page. Finally set the data-mfb-toggle attribute to click, along with the initial state you want the menu to appear at load time, using the data-mfb-state attribute. An example:

<ul class="mfb-component--tl mfb-slidein" data-mfb-toggle="click" data-mfb-state="closed">

If you want the menu to appear open at load time, do this instead:

<ul class="mfb-component--tl mfb-slidein" data-mfb-toggle="click" data-mfb-state="open">

#####Hover toggling along with touch support#####

If you want the menu to work on hover but need support for touch devices you first need to include Modernizr to detect touch support. If you are alreay using it in your project just make sure that the touch detection is enabled.

If you're not using Modernizr already, just include the provided modernizr.touch.js script (look in the src/lib/ folder) in your <head> or get the latest version of this very script right from here. Note that this is a custom build and will only detect for touch support, it's not the full library.

Then include the mfb.js file, ideally at the bottom of your page. Once the scripts are in place just set up a normal button with hover toggling like so:

<ul class="mfb-component--tl mfb-slidein" data-mfb-toggle="hover">

The script will take care of changing the behavior when the page is viewed from a touch enabled device.

#####Opening/closing the menu programmatically#####

If you need to close the menu after a certain event (or open it without user interaction) you can easily do so just by setting its state to closed or open. Once you have selected the menu in your desired way just close it like so:

menu.setAttribute('data-mfb-state', 'closed');

Or open it with:

menu.setAttribute('data-mfb-state', 'open');

##Contributions?## Yes please! If you submit a PR please add the relative documentation in this README (if needed) and don't forget to add you name and/or email to the contributors list in the package.json file.

##Credits##

##Todos##

  • provide minified script and stylesheet
  • replace @extends as much as possible from the SCSS to optimize output
  • more animations
  • add to bower
  • provide more variables/get rid of currently hard-coded values

material-floating-button's People

Contributors

cmfcmf avatar mwinandy avatar nobitagit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

material-floating-button's Issues

Icons

The icons are not appearing centered on the buttons. I have my line-height at 56px but for some reason its not working.

float_button1

Make An API for the functionality

Hey this is a pretty cool library in general. Can do the snazzy inbox + button effects with only CSS but I think it would be a good idea to at least provide a simple JS API, for example, to force the menu open and stuff without people writing custom code to pop open everything or to link a button with a specific action.

label/button spacing for smaller buttons

The site I'm working on has fairly tight spacing, so I'm using fairly small buttons and margins. With the hard-coded label placement and button stack spacing, the labels look a little strange, can overlap content:

ng-mfb_current

After poking around the sass/css available, I ended up with a layout I'm generally pleased with.

ng-mfb_patch

I added a new block of customizable variables to the scss code:

/* SPACING ---------------------------*/

// space between buttons
$default_button_padding: 30px;
$default_button_margin: 5px;

// space between button and label
$button_default_pos: 40px;

I changed your defaults in .mfb-component__list (10px for both padding and margin) to fix the spacing between buttons, and used $button_default_pos instead of 70px in the section #LABELS | Modifiers.

I'm not sure if this is a level of customization you want to support, but I thought I'd post it in case you were interested, or someone else had the same type layout. :-/

Cheers,
Cat

need advise on option for buttons

Hi there,
I would like to know if it is possible to make a variation on the floating button menu with regular images and not the icons, preferably with slightly larger (100 x 100) images
so far I only found references to making a new icon pack but I would like to implement the script for a site menu with the actual pictures of items on the site.
Thanks for your beautiful script!

Tooltips always on

Is there anyway to keep the tooltips visible all the time? ty in advance!

[MFB] Icons doesn't work well on Hexo

I use MFB to build my own site based on Hexo, It works well in localhost, but after I publish my site, I notice that the icons do not appear at all.(Git Page + Hexo)
localhost:
local
web:
web
Please help me! Thanks a lot!
Greetings!

Number of items

Hello,

Firstly, awesome job on the library. Very useful.

I have a question regarding the number of buttons allowed. I have a list of 13 buttons that I tried using, but only the first 4 are showing. I am not getting any errors, the simply do not appear. Is there a limit for the number of buttons allowed?

The documentation did not specify any limits and I assumed that there are none, but since only the first 4 are showing I thought I ask.

Thank you.

config for leaving URL fragment unchanged

If base URL is as below -
http://localhost/project/module#fragment_key=fragment_value

the plugin adds # to end of URL when click event occurs on mainButtonClass="mfb-component__button--main" and URL becomes as below -
http://localhost/project/module#

So the fragment_key and fragment_value is removed. I am opening a modal on click for menu item and would ideally have the URL unchanged so that when modal closes the fragment in URL don't change as the page has not changed

Is this possible that clicking on menu button / menu item does not lead to displacement of exisiting URL fragment in favour of "#" ?

No of Child Buttons

How can I change the number of child buttons?
I want 5 but am having difficulty in doing so.

Vertical Align Ionicons

I'm trying to implement this button on my wordpress site and I've run into an issue where the button icons are not properly aligned vertically. I can't seem to figure out why. Any chance you could help?
screenshot 2015-11-25 19 35 31

Demo animations don't change

Hi, when viewing the demo, at least on mobile, all the animations are the same. Slide, zoom, etc all do what I assume slide is. Come in from the edge slowly.

Firefox has black boxes during transition rendering

Example of animation flickering
I came across this issue when using this in firefox. I already found the solution, however my setup is quite different so I'll just provide the solution instead of sending in a pull request (I didn't generate the updated dist/ file)

Just add visibility: hidden to everywhere you use opacity: 0, and visibility: visible to any lines doing opacity: 1. Firefox seems to render the element anyhow in that distorted animation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.