JAVASCRIPT UI
Create interactive pages, no javascript required!
Ink’s vast array of UI components can be used in combination to create rich, interactive pages. They are many, and are very flexible. Javascript is not required for a lot of cases, but if you want to do more advanced stuff, you have to write some of it.
To get started, include the following JS files in the bottom of your HTML:
Although this is a page for Javascript-powered components, You will only find pure HTML examples on this page. That is because, thanks to Autoload (the autoload.js
file you loaded above) you don’t need to write any Javascript to do most things.
autoload.js
is a small Javascript file that avoids a lot of boilerplate javascript to create the UI components on this page. It does so by initializing these elements automatically (new Component(componentElement, options)
) based on their CSS class, so you don’t have to.
All Ink UI components are registered to be loaded in Autoload, with a class similar to their name. For example, to create a Modal, you add the .ink-modal
class to an element. To create a Toggle, you add a .ink-toggle
class to an element, and so on.
If you want, you can disable this behaviour. Just add data-autoload="false"
to elements without autoload, or don’t include autoload.js
at all to disable it completely.
data-option-name
vs optionName
)All configuration options, except callback functions, are available as data-attributes but are prefixed with data-
and are written in lowercase and hyphen separated: someOption
(as passed in javascript) is the same as data-some-option
(as passed in HTML).
In this page, you see a lot of javascript-powered components created only with HTML, but sometimes you need the extra edge – The power to create and destroy components any time you like, or to pass callbacks and arbitrary objects.
A responsive carousel with one or more slides per page. Cycle back and forth between slides with any content you can put in. You can also swipe back and forth with your finger if your device supports touch.
Most of the time, you will use this in conjunction with Pagination, because you want some sort of way to change pages!
This example shows you how to create a basic Carousel, use it together with a basic Pagination. It’s touch-enabled (touch support is on by default) and responsive (because it uses Ink’s CSS grid classes). As you switch to smaller devices, you’ll see that you get less slides per page to better use the viewport space.
Demo
Code
This is how you create a Carousel with chevron pagination.
To use a chevron Pagination with it, embed the .ink-pagination
element inside the .ink-carousel
element and add the chevron
class to its ul
.
Demo
Code
Add the following attributes to your .ink-carousel
element to configure your Carousel.
data-pagination="<selector>"
: Pagination element to use with this Carousel. Don’t forget this!data-initial-page="<page>"
: Carousel starts in page
. First page is 0.data-space-after-last-slide="false"
: Don’t leave blank space after the last slide.data-swipe="false"
: Disable touch support.data-auto-advance="<time>"
: Auto-advance pages every time
milliseconds.You can read the list of options to create the Carousel with JS here.
You can visit the Carousel API docs to find out about Javascript-only options, javascript methods, and how to create Carousels using Javascript
Dismiss things.
Add the ink-close
or ink-dismiss
to elements. Those elements, when clicked, will be removed. Plays well with the Alert UI Element.
Here’s an example. Click the × sign to close the alert. When you do, the element will be removed from the page.
Demo
Click the X to close this!
Code
(Close has no options)
There’s not much to know about Close, but here are the Close JS API docs.
DatePicker is a component for picking dates. You use it together with an input box, and it gets filled with the date in a certain format. The user may change the date by navigating the calendar or by typing in the input box using the correct format.
The date’s format is given in the data-format
option, where you pass a date format string in the syntax of PHP’s date()
function.
This is a simple DatePicker, mostly using the default options. It writes the dates in DD-MM-YYYY format.
Demo
Code
A DatePicker which only accepts dates between the birth of Aníbal Cavaco Silva and today.
Demo
Pick a day in the life of Aníbal Cavaco Silva:
Code
This is a DatePicker that never closes. To do this, we set it to not be “shy” (that is, don’t close automatically), and we told it to open automatically.
We also need to hide the “close” button so it doesn’t close on us, and add some CSS so that it doesn’t have position: absolute
.
Demo
Code
Add the following attributes to your .ink-datepicker
input element to configure your DatePicker.
data-start-date="<yyyy>-<mm>-<dd>"
: Start with a certain date. Defaults to today.data-date-range="<start>:<end>"
: Only allow dates between start
and end
. Don’t forget the :
:).data-format="d-m-Y"
: Date format string. Uses the same syntax as PHP’s date()
function. Let’s see how they format the date “15th July of 1939”:
data-format="d-m-Y"
- “15-07-1939”data-format="Y/d/m"
- “1939/15/07”data-format="Y-m-d"
- “1939-07-15”data-clean-text="<word>"
: Text for the “Clear” button.data-close-text="<word>"
: Text for the “Close” button.data-of-text="<of>"
: Text to show between month and year. Defaults to ‘ of ‘.data-next-link-text="<text>"
: Text for the next button. Defaults to ‘»’.data-prev-link-text="<text>"
: Text for the previous button. Defaults to ‘«’.data-start-week-day="<day>"
: First day of the week. Sunday is zero. Defaults to 1 (Monday).data-show-clean="false"
: Hide the “Clear” button.data-show-close="false"
: Hide the “Close” button.data-auto-open="true"
: The DatePicker will be initially openeddata-shy="false"
: Stop the DatePicker from closing itself automatically.data-css-class="ink-calendar <my classes>"
: Add classes to the DatePicker.data-on-focus="false"
: Add this if you don’t want the DatePicker to open itself when you click the input.data-picker-field="<selector>"
: (if not using in an input[type=”text”]) Element which displays the DatePicker when clicked. Defaults to an “open” link.data-position="right"
: Float the DatePicker to the right.<select>
elements instead of an <input>
element.Options to use DatePicker with <select>
elements. They require data-display-in-select="true"
.
data-display-in-select="true"
: Enable this first.data-day-field="<selector>"
: <select>
field with the days.data-month-field="<selector>"
: <select>
field with the months.data-year-field="<selector>"
: <select>
field with the years.You can read the list of options to create the DatePicker with JS here.
You can visit the DatePicker API docs to find out about Javascript-only options, javascript methods, and how to create DatePickers using Javascript
Draggable is a component which works with Droppable.
Drag some draggables around!
Demo
Code
These Draggables can’t move freely, they’re constrained inside certain boundaries.
Demo
Code
data-constraint="<vertical, horizontal or both>"
- Constrain Draggable movement in an axis. None by default. Can be vertical
, horizontal
, or both
. By default movement is not constrained.data-constraint-elm="#my-div"
- Only drag inside #my-div
. Make sure that element has a min-height
to avoid weird behaviour.data-handle=".drag-here"
- The element with the .drag-here
class will be used as a handle for dragging.data-revert="true"
- Revert the draggable to its original position when dropped.data-cursor="pointer"
- Set the mouse to pointer
while hovering this Draggable, instead of move
. Valid options here are the values of the CSS cursor
property.data-z-index="100"
- Set the z-index to 100 while dragging.data-fps="12"
- Move things at most 12 times per second. Use this to limit the CPU resources needed to perfrom a drag action.data-mouse-anchor="<anchor>"
- Anchor for the drag. Can be one of: "left"
, "center"
, "right"
, "top"
, "center"
, "bottom"
.data-drag-class="im-dragging"
- Add the .im-dragging
class when this draggable is being dragged.data-skip-children="false"
- Dragging children of this element doesn’t count.If you set a data-constraint
or data-constraint-elm
option (see above), these can be used to determine how far from the constraint areas the Draggable can move. Try them out:
data-top="10"
- Always stay 10px away from the top.data-right="10"
- Always stay 10px away from the right.data-bottom="10"
- Always stay 10px away from the bottom.data-left="10"
- Always stay 10px away from the left.You can visit the Draggable API docs to find out about Javascript-only options, javascript methods, and how to create Draggables using Javascript
Drawer is a component showing off-canvas menus which slide in when their toggle is clicked or touched. It’s useful for saving precious screen real estate on devices with small screens.
It slides in from one of the sides, either pushing or going over (this is configurable) the page’s content.
You need to place your entire page’s content inside an element with the class content-drawer
, so that it may be pushed aside.
This is a simple Drawer coming in from the left.
Demo
Code
This is an example of two drawers, one coming from the right and one from the left.
Demo
Code
'over'
modeThis drawer goes over the page content, instead of pushing it.
Demo
Code
data-mode="over"
- Make the drawer go over the body instead of pushing it.data-sides="<side>"
- Make a drawer that comes in from this side
. Can be ‘left’, ‘right’, or ‘both’.data-content-drawer="#my-content-div"
- Your main page container.data-left-drawer=".my-left-drawer"
- Left drawer (the element that is placed offcanvas). This should be a sibling of your data-content-drawer
element.data-left-trigger=".my-left-trigger"
- Left drawer trigger(s). When you click this trigger, the leftDrawer
is shown.data-right-drawer=".my-right-drawer"
- Right drawer (the element that is placed offcanvas). This should be a sibling of your data-content-drawer
element.data-right-trigger=".my-right-trigger"
- Right drawer trigger(s). When you click this trigger, the rightDrawer
is shown.You can visit the Drawer API docs to find out about Javascript-only options, javascript methods, and how to create Drawers using Javascript
Dropdown is designed to add dropdown menus. They are a simplified version of Toggle, which is much more complex, and they work better with nested menus without a lot of the hassle which goes into creating them using Toggle.
It also includes some mouse-away logic, so as to avoid the dropdown being open forever if your mouse moves away from the dropdown. This is activated using data-dismiss-after="<s>"
where s
is your time in seconds which it is supposed to stay open.
This is a simple Dropdown menu.
Demo
Code
By adding the data-dismiss-after="<s>"
option, the Dropdown will go away automatically after s
seconds pass.
Here we hide it after 2 seconds.
Demo
Code
data-target="#my-menu"
- Make #my-menu
the ul
which this Dropdown opens.data-hover-open="<seconds>"
- The number of seconds you need to hover with the mouse before the dropdown opens.data-dismiss-after="<seconds>"
- When the mouse moves away from the dropdown, wait for seconds
seconds and then dismiss.data-dismiss-on-inside-click="true"
- Dismiss the dropdown when there’s a click inside.data-dismiss-on-outside-click="false"
- Do not dismiss the dropdown when there’s a click outside.You can visit the Dropdown API docs to find out about Javascript-only options, javascript methods, and how to create Dropdowns using Javascript
The Droppable is a dropping area for Draggables. It’s useful to create shopping carts, playlists, and other things which rely on dragging and dropping action.
Let’s drag a couple of Draggables into a droppable!
Demo
A droppable
A couple of draggables
Code
You can choose what Draggables get dropped in your droppable! Here we see only green Draggables accepted in a Droppable.
Demo
Drop only green things here:
A couple of draggables
Code
data-hover-class="hoverin"
- Add the .hoverin
class when a Draggable and hovering this droppable.data-accept=".only-these-draggables"
- Accept only elements with the class .only-these-draggables
.These options can be further customized using javascript. Without javascript, though, there are already a few pre-made actions.
These actions are "move"
and "copy"
, which move or copy the draggable element into this draggable, or "revert"
, which puts the draggable right back where it came from..
data-on-drop="<move copy or revert>"
- When an element is dropped, move or copy it here, or revert it to where it came from.data-on-hover="<move copy or revert>"
- When an element is hovering the droppable, move or copy it here, or revert it to where it came from.data-on-drop-out="<move copy or revert>"
- When a Draggable is dropped outside of this droppable, move or copy it here, or revert it to where it came from.You can visit the Droppable API docs to find out about Javascript-only options, javascript methods, and how to create Droppables using Javascript
FormValidator is a component which validates forms interactively on the client side before any data is sent to the server. By doing this, it provides a less waiting time, and a better experience to the user.
To use FormValidator, add the .ink-formvalidator
class to a <form>
element. Ink won’t let the user submit until the data is valid.
You will probably need to read the Forms UI Element documentation to get to grips with the classes used. TL;DR: .ink-form
goes outside, .control-group
is nestable and groups similar controls, and .control
wraps the inputs.
Here is a simple example of a user registration field:
Demo
Note: The required
class is related to the Form UI Element. it doesn’t affect the FormValidator’s behaviour.
Code
Here’s how FormValidator deals with <input type="radio">
and <input type="checkbox">
inputs.
Demo
Note: The required
class is related to the Form UI Element. it doesn’t affect the FormValidator’s behaviour.
Code
To issue a custom error message for that input, add a data-error attribute to the element
Demo
Note: The required
class is related to the Form UI Element. it doesn’t affect the FormValidator’s behaviour.
Code
Put this in your <form>
if you want to translate the form. Options to define the validation of each input are below.
data-lang="pt_PT"
- Write error messages in portuguese. Languages available are pt_PT
and en_US
but others can be added through javascript.After adding the .ink-formvalidator
class to your FormValidator, add these data-attributes to your form inputs (input, select, textarea…) to configure how they are validated.
Each field (<input>
, <select>
, <textarea>
, etc.) which you want to validate in your form needs to have “rules”. These rules define what can go and what can’t go on this element. Read more on them in “Validation rules”, below.
data-rules="Field name in human-readable form"
- Rules for this field. Read more in the “Validation rules” section, below.data-label="Field name text"
- The name of this field. It is used to show in error messages. By default the label is the name
attribute of your field.This is what you put in data-rules
for each element. Here are a few examples of what you can do:
data-rules="required"
- Must be filled in.data-rules="alpha"
- Just alphabetic characters (A to Z), lower case or upper case.data-rules="alpha_numeric"
- Like alpha
but accepts numbers too!data-rules="credit_card"
- A credit card number.data-rules="email"
- A valid e-mail.data-rules="range[0,10]"
- Numbers (not exactly integers) between 0 and 10.data-rules="numeric[.]"
- A numeric field, using the .
as a decimal separator. (Ex: “1.5”)data-rules="numeric[.,2]"
- A numeric field with at most 2 decimal places. (“1.23” is okay but “1.234” is not)data-rules="numeric[.,2,4]"
- A numeric field with at most 2 decimal places and at most 4 digits on the left. (“1234.56” is okay but “12345.6” and “1234.567” are not)data-rules="integer"
- Only whole numbers.You can combine these rules, like this:
data-rules="required|number"
- A required number.data-rules="required|email"
- A required email.data-rules="integer|range[0,10]"
- A whole number between 0 and 10.Some assorted rules which are useful in combination with other rules:
data-rules="min_length[4]"
- Must have at least 4 characters.data-rules="max_length[4]"
- Can’t have more than 4 characters.data-rules="exact_length[4]"
- Must have exactly 4 characters.Random rules you might need:
data-rules="color"
- A color in #hex
, rgb()
, rgba()
, hsl()
, hsla()
format.data-rules="date[<format>]"
- A date. format
is a date format string in the syntax of PHP’s date()
functiondata-rules="decimal[...]"
- Exactly like numeric
but only decimal numbers are allowed.data-rules="ip[ipv6]"
- An IP address.data-rules="ip[ipv4]"
- A legacy IP address.data-rules="phone[PT]"
- A Portuguese phone number.data-rules="phone[CV]"
- A Cape Verde phone number.data-rules="phone[AO]"
- An Angolan phone number.data-rules="phone[MZ]"
- A Mozambique phone number.data-rules="phone[TL]"
- A Timor phone number.data-rules="phone"
- Any of the above types of phone number.data-rules="url"
- A URL. (Ex: "/foo/bar"
, "https://example.com/foo/bar"
, etc.)data-rules="url[true]"
- Just like url
but only if it contains the “https://” part.data-rules="ean"
- A barcode in EAN-13 format.You can see more validation rules, as well as a more in-depth description of each one of them, in the JS documentation for FormValidator.validationFunctions
You can visit the FormValidator_2 API docs to find out about Javascript-only options, javascript methods, and how to use FormValidator using Javascript.
LazyLoad delays the downloading of images, showing them only when they get to the viewport. This is useful in optimizing image-heavy websites.
You can use the more advanced Javascript API to load things other than images, such as widgets, videos, active content, etc.
While the images are loading or offscreen, their appearance will be a simple, more lightweight, placeholder. You can define what this placeholder using the data-placeholder
option of the LazyLoad, about which you can learn about below, in “LazyLoad options for the container”.
A LazyLoad is comprised of a container element, which can be the <body>
if you like, with the class .ink-lazyload
, and LazyLoad items, with the class .lazyload-item
, and with a data-src
attribute instead of a src
attribute.
It is recommended that you make sure, using CSS, that the images will take as much space after they loaded as before loading. In other words, reserve space for your images! This avoids weird scrolling issues.
The images below will only load when you scroll
Demo
Code
When images are loaded, they will get a new CSS class and have a pretty fade-in!
Demo
Code
data-src="/my/image.png"
- The real source of the image, only loaded when the image is on screen.data-placeholder="/my-loading-spinner.gif"
- Placeholder value for items which are not ‘visible’, in case they don’t already have a value set.data-loaded-class="loaded"
- Add the “loaded” class to the images when they’re loaded.data-delta="100"
- Start loading the images 100px before they are on the screen.data-delta="-100"
- Start loading the images 100px after they are on the screen.data-delay="1000"
- Wait 1000 milliseconds (1 second) before showing the image.data-item=".my-crazy-selector"
- Find images by .my-crazy-selector
instead of finding images with the .lazyload-item
class.You can visit the LazyLoad API docs to find out about Javascript-only options, javascript methods, and how to use LazyLoaders with Javascript. There’s more advanced stuff that isn’t covered here, like loading non-image elements with callbacks.
The Modal component allows you to overlay something on the entire page, possibly an error message that refers to the whole page, or a follow-up form or dialog to a submission process.
It works by putting a shade element with position:fixed
covering the entire viewport and avoiding accidental interaction with the rest of the page, and placing a modal element on the center of the screen using javascript.
It plays well with the .ink-dismiss
class (the Close element). An element with the ink-dismiss
class dismisses the modal that contains it.
Click the button to open a modal
Demo
Code
Besides the content, this modal has a dismiss button, a header and a footer, besides the content.
Demo
Code
To automatically open the modal, just omit the trigger!
Demo
Code
data-trigger="#my-button"
- The modal will open when #my-button
is clicked.data-width="600px"
- Make the modal 600px wide.data-height="400px"
- Make the modal 400px tall.data-width="40%"
- Make the modal width be 40% of the screen width.data-height="20%"
- Make the modal’s height be 20% of the screen height.data-auto-display="true"
- Displays the Modal automatically when constructed.data-close-on-click="false"
- Don’t close when the user clicks outside the modal.data-close-on-escape="false"
- Don’t close the modal when ESC is pressed.data-responsive="false"
- Don’t resize the modal when the screen is resized.You can visit the Modal API docs to find out about Javascript-only options, javascript methods, and how to use Modals with Javascript and subscribe to their events.
You can use Pagination when you need interactive paginators. It does not paginate anything by itself and must be connected to some other piece of javascript to do anything useful. Above you see it used together with Carousel to change its pages.
It uses the CSS you see in the Pagination UI Element (CSS). If you want a static pagination, just use that. If you really want a dynamic pagination, read on.
Here we use the data-size
option to tell Pagination how many pages it is paginating.
Demo
Code
This example shows you how to deal with showing 100 pages without having all the numbers 1, 2, 3, 4... 100
written down.
This is effectively the Pagination paginating itself :)
Demo
Code
You can define the page count in two ways. One of them is just saying how many pages you have. The other is by telling it how many items you have, and how many items per page you need. Pagination will do the math for you in this case and calculate the page count by itself.
Here is how you define the page count directly:
data-size="<size>"
- Define the page count to be size
, directly.Here’s how you tell Pagination to do the math for you:
data-total-item-count="<item_count>"
- Tell Pagination you have item_count
items (don’t forget the below option too!).data-items-per-page="<per_page>"
- Tell Pagination you plan to display per_page
items per page.data-max-size="<max>"
- Show at most max
numbers. This enables the “Next N”, “Previous N” buttons.data-previous-page-class="<class>"
- Add class
to the “previous N” button.data-next-page-class="<class>"
- Add class
to the “next N” button.data-first-label="<text>"
- Write text
on the first page button instead of ‘First’.data-last-label="<text>"
- Write text
on the last page button instead of ‘Last’.data-previous-label="<text>"
- Write text
on the previous button instead of ‘Previous’-data-next-label="<text>"
- Write text
on the next button instead of ‘Next’data-previous-page-label="<text>"
- Write text
on the previous page button instead of ‘Previous {Items per page}’.data-next-page-label="<text>"
- Write text
on the next page button instead of ‘Next {Items per page}’.data-pagination-class="<class>
- Class for the pagination elementdata-active-class="<class>
- Class that marks page as active (current page number)data-disabled-class="<class>
- Class that marks a page as disableddata-previous-class="<class>
- Class for the “previous” elementdata-next-class="<class>
- Class for the “next” elemntdata-hide-class="<class>
- Class which hides elementsdata-start="3"
- Start in page 3 instead of page 1.data-side-buttons="false"
- Hide the first, last, previous, next, “previous N” and “next N” buttons. Do not use together with data-max-size
.data-auto-wrap="true"
- Navigate to first page when clicking “next” in the last page and vice-versa.data-parent-tag
- HTML Tag used as the parent node.data-child-tag
- HTML Tag used as the child nodes.You can visit the Pagination API docs to find out about Javascript-only options, javascript methods, and how to use Paginations with Javascript and subscribe to their events.
A ProgressBar can be used to indicate progress in a certain process.
This is a progress bar. The process is well under way, it seems, at 70%.
Demo
Code
Use this vast array of options to customize your ProgressBar:
data-start-value="20"
- Start at 20% instead of 0%.You can also use some color classes (instead of grey
) to color your progress bar.
You can visit the ProgressBar API docs to learn how to create ProgressBars with javascript and manipulate them in real time.
SmoothScroller is a component for
This shows you how to set a couple of anchor links which, when clicked, scroll smoothly up to their destination. Here are two links and sections:
Demo
[lots and lots of content...]
...
Part 1 content
Part 2 content
Code
This example shows the use of data-margin
to scroll up to 200px above the target.
The data-margin
option is very useful if you have a position:fixed
menu or top bar on the top of your page. Using it avoids hiding important content behind that bar.
Demo
[lots and lots of content...]
...
I am something!
Code
Here is how you use data-speed
to scroll really fast. It defaults to "10"
. Smaller is faster, larger is slower.
Demo
[lots and lots of content...]
...
Thing 1 fast!
Thing 2 fast!
Code
When a link is clicked, it is checked for several things:
href="#my-item-id"
- Scroll up to the element with ID my-item-id
. Only works with IDs, just like regular anchor links.data-margin="42"
- When scrolling, leave a 42px margin above the target. Useful if you have a 42px-tall position:fixed
top bar.data-speed="5"
- Scroll faster.data-speed="20"
- Scroll slower.data-change-hash="false"
- Don’t change the URL hash (#hash
), just scroll there.You can visit the SmoothScroller API docs to find out about Javascript-only options, javascript methods, and how to use SmoothScrollers with Javascript and subscribe to their events.
SortableList turns a list into a list which can be sorted by the user using the mouse. It does not currently work with touch events.
A handle can be selected, in which case the user will only be able to drag the list items by that handle (something like a “drag here” icon). SortableList can also be used to sort non-list elements.
Let’s sort a few items:
Demo
Code
While you’re dragging, the dragged item gets the “placeholder” CSS class, enabling you to style it as you like.
Demo
Code
SortableList will also add the drag
class to the <html>
element while
you sort things. You can change it to another class using data-dragging-class
.
Demo
Code
In this example, you can only drag by the “bars” icon to the left of each word.
Demo
Code
Here’s a sortable table. Notice that we use data-drag-selector="tbody tr"
, to
tell SortableList what is being sorted is the rows inside the <tbody>
element.
Demo
Name | Number |
---|---|
First | 1 |
Second | 2 |
Third | 3 |
Code
Below you can see two sortable grids, just to show off two ways of sorting items.
When “swap mode” is active, the sorting makes more sense in grids, although it changes the list around a lot.
Demo
Code
These options help you configure SortableList. Most of them have a working example above.
data-placeholder-class="my-placeholder"
- Add the my-placeholder
class to the dragged placeholder. By default the placeholder
class is added.data-dragging-class="html-element-with-things-being-dragged"
- Add this class to the <html>
element when something is dragged. By default, the dragging
class is added.data-drag-selector=".my-dragged-items"
- Sort .my-dragged-items
instead of li
elements. You see this in use above in “Sorting non-list elements”.data-handle-selector=".handle"
- Drag nodes by a handle, marked by the .handle
class. This handle must be inside the dragged node.data-swap="true"
- Instead of reordering items, swap them. Makes a lot of sense when sorting grids, but does nothing in simple lists.data-cancel-mouse-out="true"
- Stop dragging if the mouse leaves the container.You can visit the SortableList API docs to find out about Javascript-only options, javascript methods, and how to use SortableLists with Javascript.
Spy is a simple way to help the user keep track of where they are when scrolling your page.
As a user scrolls down the page and changes to new sections (they may be actual
<section>
elements or whatever you like), Spy will highlight the corresponding
link on your menu. This is useful when your menu has position:fixed
and has a
bunch of anchor links to several parts of the page.
Your menu must have all links inside li
tags. These will get the .active
class. You then style the .active
class as you like.
A bunch of sections
Demo
Code
There’s only one option to Spy.
data-target="#the-target"
- Make #the-target
the spy target.You can visit the Spy API docs to find out about Javascript-only options, javascript methods, and how to create Spies using Javascript
Stacker will reorganize N columns when the screen is not wide enough to show them all. It will mash together the contents of the 3 columns
It does so to avoid the problem of the elements’ unknown height
This example re-stacks 3 feeds of data in the large viewport into a single column in the small viewport. Resize your viewport and watch the items get mashed together.
Demo
Code
This example shows off Stacker’s capacity to deal with multiple height items even as the screen width forces it to reduce the amount of columns. It contrasts a “classic” way to do things with the “Stacker” way to achieve a similar result.
Demo
Code
data-large-cols="5"
- Have 5 columns in the large viewport instead of 3.data-medium-cols="3"
- Have 3 column in the medium viewport instead of 3.data-small-cols="2"
- Have 2 columns in the small viewport instead of 1.data-item=".my-stacker-item
” - Your stacker items. This defaults to .stacker-item
.data-column=".my-stacker-columns"
- If for some reason you don’t want to use the stacker-column
class to identify your stacker columns, you can use this option to change it.data-is-ordered="false"
- Don’t reorder the stacks when resizing.You can visit the Stacker API docs to find out about Javascript-only options, javascript methods, and how to create Stackers using Javascript
Here is sticky’s default behavior. No options, sticking an alert to the top of the screen.
Demo
Code
When a sticky is stuck to the top of the screen, it gets the .ink-sticky-stuck
class. You can use that to style your sticky differently when it’s stuck!
Demo
Code
This option is very useful for large footers, which don’t play well with sticky elements hovering on top of them.
It also works well when the Sticky only refers to a section and you wouldn’t want it flying off of it because that would be confusing.
Just add data-bottom-element="#bottom-element
and Sticky will avoid going below that element.
Demo
Code
data-top-element="#top-element"
- Don’t let the sticky go above or run into this element.data-bottom-element="#bottom-element"
- Don’t let the sticky go below or run into this element.data-offset-top="20px"
- Instead of sticking right to the top of the screen, keep a margin of 20px. This is very, very useful, if you already have a position:fixed
top bar on your page.data-offset-bottom="10px"
- Like data-offset-top
, but for the bottom. Avoids the sticky sticking right to the bottom of the screen.data-inline-dimensions="false"
- Tell sticky to not mess with your element’s style
to set dimensions. You may want to do this because you want to set the dimensions yourself in your CSS for .ink-sticky
or .ink-sticky-stuck
.data-inline-position="false"
- Tell sticky to not mess with your element’s style
to set position. You may want to do this because you want to set the position yourself in your CSS for .ink-sticky
or .ink-sticky-stuck
.data-wrapper-class="my-wrapper"
- Add this class to the sticky wrapper (the DIV that stands in place for the element when it is put in position:fixed
).data-sticky-class="i-am-stuck"
- Add this class to the sticky when it’s stuck (position:fixed
) on the top or bottom of the screen.You can visit the Sticky API docs to find out about Javascript-only options, javascript methods, and how to create Stickies using Javascript
The Tabs Component offers a simple way to build a tab-separated layout, allowing you to offer multiple content panes in the same space with intuitive navigation. This component requires your markup to have:
.tabs-nav
class, containing links with the [href]
attribute set to the ID of the section they point at. Like regular in-document anchor links..tabs-content
class.A simple Tabs component, with tabs on top and two sections.
Demo
A home is a dwelling-place used as a permanent or semi-permanent residence for an individual, family, household or several families in a tribe. It is often a house, apartment, or other building, or alternatively a mobile home, houseboat, yurt or any other portable shelter. Larger groups may live in a nursing home, children's home, convent or any similar institution. A homestead also includes agricultural land and facilities for domesticated animals. Where more secure dwellings are not available, people may live in the informal and sometimes illegal shacks found in slums and shanty towns. More generally, "home" may be considered to be a geographic area, such as a town, village, suburb, city, or country
News is the communication of selected[1] information on current events. It is shared in various ways: among individuals and small groups (such as by word of mouth or newsletters); with wider audiences (such as by publishing, either in print or online, or broadcasting, such as on television or radio); or in ways that blend those traits (such as when social media sharing starts among individuals but goes viral).
Code
This example shows you how to change the position of the tabs to have them hanging from the left by adding the .left
class to the .ink-tabs
element. You can also use "top"
(shown above), "bottom"
, or "right"
.
Demo
A home2 is a dwelling-place used as a permanent or semi-permanent residence for an individual, family, household or several families in a tribe. It is often a house, apartment, or other building, or alternatively a mobile home2, houseboat, yurt or any other portable shelter. Larger groups may live in a nursing home2, children's home2, convent or any similar institution. A home2stead also includes agricultural land and facilities for domesticated animals. Where more secure dwellings are not available, people may live in the informal and sometimes illegal shacks found in slums and shanty towns. More generally, "home2" may be considered to be a geographic area, such as a town, village, suburb, city, or country
News is the communication of selected[1] information on current events. It is shared in various ways: among individuals and small groups (such as by word of mouth or news2letters); with wider audiences (such as by publishing, either in print or online, or broadcasting, such as on television or radio); or in ways that blend those traits (such as when social media sharing starts among individuals but goes viral).
Code
The li
containing the tab gets the .active
class when it is active. You can use that as a CSS hook to style the active tab differently. .tabs-content
also gets the .active
class when it’s active.
Demo
A home3 is a dwelling-place used as a permanent or semi-permanent residence for an individual, family, household or several families in a tribe. It is often a house, apartment, or other building, or alternatively a mobile home3, houseboat, yurt or any other portable shelter. Larger groups may live in a nursing home3, children's home3, convent or any similar institution. A home3stead also includes agricultural land and facilities for domesticated animals. Where more secure dwellings are not available, people may live in the informal and sometimes illegal shacks found in slums and shanty towns. More generally, "home3" may be considered to be a geographic area, such as a town, village, suburb, city, or country
News is the communication of selected[1] information on current events. It is shared in various ways: among individuals and small groups (such as by word of mouth or news2letters); with wider audiences (such as by publishing, either in print or online, or broadcasting, such as on television or radio); or in ways that blend those traits (such as when social media sharing starts among individuals but goes viral).
Code
data-prevent-url-change="true"
- Don’t change the URL #hash
when a tab is clicked.data-active="my-tab"
- Activate the tab with id="my-tab"
by default. Otherwise, it will be whatever is on the URL #hash
, or the first tab in the ul
.data-menu-selector=".my-tabs-nav"
- Your tab links. Use this if you don’t want to use the .tabs-nav
class.data-content-selector=".my-tabs-content"
- Your tab content panes. Use this if you don’t want to use the .tabs-content
class.You can visit the Tabs API docs to find out about Javascript-only options, javascript methods, and how to create Tabs using Javascript
Toggle is a component for showing and hiding things. It can be made to do far more.
Since “showing” and “hiding” is just adding and removing classes, by changing the added and removed classes, you can achieve a lot with styling hooks.
A Toggle can also coordinate with other sibling toggles and create an accordion using data-is-accordion="true"
.
Demo
Code
By using the data-class-name-on
and data-class-name-off
options you can customize what classes get added and removed from your toggle targets. Here’s how you choose between two classes on an element.
Demo
Code
We can also style our button according to toggle state. Toggle will add the .active
class to the toggle element, in this case the button
.
Demo
Code
Toggle is capable of toggling many targets. It will toggle everything you select in data-target
.
Demo
Code
You can use Toggle to achieve an accordion! Just add the data-is-accordion="true"
option to all accordion parts, and make sure they’re direct children of a div with the class .accordion
.
Demo
See more 1
See more 2
See more 3
See more 4
Code
Here’s how you put an accordion inside an accordion.
Just make sure to add the div with the class .accordion
and place the inner accordion inside that. It should work well :)
Demo
See more 1
See more 2
See more 3
Code
data-is-accordion="true"
- This toggle is a part of an accordion. Make sure it is the direct child of an element with the class .accordion
. Otherwise, Ink will warn you about this on the console.data-class-name-on="my-on-class"
- Add the .my-on-class
class when the toggle is ON. Use this for styling hooks.data-class-name-off="my-off-class"
- Add the .my-off-class
class when the toggle is OFF. Use this for styling hooks.data-close-on-click="false"
- Don’t toggle OFF when clicking outside.data-can-toggle-an-ancestor="true"
- Use this if you wish to toggle nodes which are ancestors of this node (for instance <div class="ancestor"><yourtoggleelement/></div>
.data-close-on-inside-click=".some-class"
- Toggle off when a child element with the class .some-class
is clicked. By default toggle will toggle itself off when a link is clicked.data-initial-state="true"
- Toggle is ON initially.data-initial-state="false"
- Toggle is OFF initially.You can visit the Toggle API docs to find out about Javascript-only options, javascript methods, and how to create Toggles using Javascript
Hover these labels:
Demo
Code
You can set the tooltip’s inner HTML by using data-tip-html="(my html)"
.
Demo
Hover me
Code
You can replace the tooltip structure (the rounded rectangle with the triangle arrow) entirely by using data-tip-template="#my-template-id"
and data-tip-templatefield=".write-tip-text-here"
.
Demo
Code
Hover these labels:
Demo
Using data-tip-where="up"
(default)
Using data-tip-where="down"
Using data-tip-where="left"
Using data-tip-where="right"
Using data-tip-where="mousemove"
Using data-tip-where="mousefix"
Code
data-tip-text="<tooltip text!>"
- Text content for the tooltip.data-tip-html="<tooltip inner HTML>"
- HTML for the tooltip. Use this instead of data-tip-text
when you need to add arbitrary HTML instead of just text.data-tip-where="down"
- Make the tooltip appear below the element instead of above. You can also use 'left'
or 'right'
. See below to find out how to place the tooltip relative to the mouse.data-tip-color="red"
- Make the tooltip be red! The tooltip can be colored red
, orange
, blue
, green
and black
. Default is white
.data-tip-fade="0.5"
- Take 0.5s to fade in and out.data-tip-forever="true"
- Make the tooltip not disappear even if the mouse goes away. If FOREVER is too long to wait use data-tip-timeout
to set a time to live.data-tip-timeout="10"
- The tooltip will stay open for 10 seconds. Useful with data-tip-forever="true"
, and it won’tdata-tip-delay="1.1"
- Wait 1.1s before showing the tooltip. Useful to avoid getting the attention of the user unnecessarily.data-tip-template="#my-template"
- An element to use as the tooltip template instead of the default rectangle and arrow. See above for an example.data-tip-templatefield=".write-text-here"
- When using data-tip-template
, tell Tooltip to write the text in the .write-text-here
element.Positioning relative to the mouse is easy and requires only one of these options:
data-tip-where="mousemove"
- Tooltip follows the mouse.data-tip-where="mousefix"
- Tooltip stays in place where the mouse first touched the element.When the tooltip is positioned relative to the mouse, these two allow you to tweak how far from the mouse they are.
data-tip-left="20"
- place the tooltip 20px to the right of the mouse.data-tip-top="20"
- place the tooltip 20px below the mouse.You can visit the Tooltip API docs to find out about Javascript-only options, javascript methods, and how to create Tooltips using Javascript
Shows elements in a tree view whose nodes can be expanded and contracted.
A TreeView consists of “nodes” and “children”, which are elements which have child nodes.
Demo
Code
data-node=".node"
- Make tree nodes be elements with the .node
class instead of any li
element.data-children=".cont"
- Make the children containers be elements with the .cont
class.data-parent-class="i-am-parent"
- Add the .i-am-parent
class to nodes which have children.data-open-class="fa fa-check-circle"
- Add the .fa-check-circle
, .fa
classes to the icon when nodes are open. Use this to override the default icons.data-closed-class="fa-circle"
- Add the .fa-circle
, .fa
classes to the icon when nodes are closed. Use this to override the default icons.data-hide-class="invisible"
- Add the .invisible
class to “children” elements to when they are hidden. Defaults to hide-all
.data-icon-tag="span"
- Use a span
instead of an i
for the icon.You can visit the TreeView API docs to find out about Javascript-only options, javascript methods, and how to create TreeViews using Javascript