npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery.rsbutton

v1.0.2

Published

Shows intermediate sprites when running a transition between two states

Downloads

5

Readme

jquery-rsButton Build Status

Animates a toggle control (most commonly a button) with several frames for a realistic state transition look.

Every toggle control has two states: unpressed and pressed. When a button is clicked, the state changes from unpressed to pressed and remains pressed while its down. Once it releases, the state moves back from pressed to unpressed. This plug-in simply displays intermediate frames between these two states, through the use of CSS classes, one class for each frame.

Here is an example:

    <button class="btn">sample frame</button>
    $(".btn").rsButton({
        frameClasses: ['frm1', 'frm2', 'frm3', 'frm4']
    });

When a button is pressed, the frm1, frm2, frm3 and frm4 are displayed one after another for 60 milliseconds (you can change the frame delay).
frames
Notice the subtle differences between these four frames and the changes made to the markup during this process.

When a button is released, the frames are displayed in oposite order: frm4, frm3, frm2 and frm1.
Live demo here.

#Faq ###I dislike the colors and style. Is it possible to change? Sure it is possible to change.
For reasons related with performance and responsive design, each frame is made out of pure CSS with relative em units. They are not images at all. These relative units should always be used, even if you wish to use a fixed size layout.
For your convenience, there is a LESS file at src/rsButton.less where you can change the frames to your preference. If you are interested in changing only the color palette, you can change the @background variable in the LESS file.
However, nothing stops you from using images for each frame, although that might cause performance and responsive design issues later on.

###Do I need to specify that btn class? Yes, if you want a 3D layout to your buttons.
If you prefer a flat layout, then use the class btnflat instead.
Notice that you are free to use whatever class you want, just make sure it is also defined in the src/rsButton.less.

###Why my <input class="btn"> element looks flat and not 3D alike? In the src/rsButton.less you can see that the 3D look is achived via the :before and :after pseudo-classes.
These pseudo-classes cannot be applied to input elements, since they are not block elements, they are inline, and therefore input elements can only have a flat layout.

###Is it limited to 4 frames? No, you can use as many frames you wish. If you only use 1 or 2 frames, then there is no point using this plug-in, since that can be easly done with CSS alone.
You need to make sure the frames you specify in frameClasses property are defined in the LESS file.

###How can I compile LESS into CSS? Run

grunt less

It creates a new dist/rsButton.css file.

###This plug-in can only be used for push buttons? No. It can be used for any control that switches from state A to state B when pressed down and from state B to A when released.
This means that this plug-in works for any markup, not only for <button>.
Since the most common control with this behaviour is a push button, hence the plug-in name.

###Cannot this be done with CSS alone? It depends...
Yes, if you want to simply smooth (interpolate) frames between a start and an end frame. In this case, you should not use this plug-in and must resort to CSS transitions.
No, if you want to design specific frames that are distinct from each other and thus not possible to replicate via CSS transitions.

###Why cannot use CSS animations to specify distinct frames? You almost can with CSS3 animations.
By default, CSS3 animations perform interpolations between the animation steps. Since we don't want any frame interpolation (because we define how each frame exactly looks), we need to specify either step-start or step-end as your timing function.
You also need two animations:

  • When the control is pressed down, the one that animates the state transition from unpressed to pressed. Easly implemented with the :active pseudo-class. When this animation finishes, it needs to stay on the last frame, so animation-fill-mode should be set to forwards. The animation shows the frames frm1 -> frm2 -> frm3 -> frm4 and stays on frm4 when animation finishes.
  • When the control is released, the one that animates the state transition from pressed to unpressed. This has to be triggered when not in :active, which means that should be the default animation. The animation shows the frames frm4 -> frm3 -> frm2 -> frm1.
/* frm1 style goes here */

@keyframes pressAnim {
    33%  { /* frm2 style goes here */ }
    66%  { /* frm3 style goes here */ }
    100% { /* frm4 style goes here */ }
}

@keyframes releaseAnim {
    0%  { /* frm4 style goes here */ }
    33% { /* frm3 style goes here */ }
    66% { /* frm2 style goes here */ }
}

button.btn {
    animation: releaseAnim .5s step-end;
}

button.btn:active {
    animation: pressAnim .5s forwards step-end;
}

Basically, there are three problems with this approach:

  • The second animation (releaseAnim) runs at page load time;
  • If the user presses and releases the button too quickly, before the first animation (pressAnim) finishes, an ugly "jump" to the second animation will be noticed. That is, considering the use case with 4 frames, if a button is pressed down and released so quickly that only the first two frames were displayed, the final chained animation will look like frm1 -> frm2 -> frm4 -> frm3 -> frm2 -> frm1;
  • Lack of cross-browser support.

Due to the above problems, a decision was made to implement this functionality in JavaScript.

#Key Features

  • Works with any HTML element;
  • Desktop and mobile devices;
  • Optionally uses the keyboard (space or Enter);
  • Small footprint.

#Installation

You can install from npm:

npm install jquery.rsbutton --save

or directly from git:

<script src="http://rawgit.com/ruisoftware/jquery-rsButton/master/src/jquery.rsButton.js"></script>

or you can download the Zip archive from github, clone or fork this repository and include jquery.rsButton.js from your local machine.

You also need to download jQuery. In the example below, jQuery is downloaded from Google cdn.

#Usage

<!doctype html>
<html>
<head>
    <title>jquery-rsButton plug-in</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="http://rawgit.com/ruisoftware/jquery-rsButton/master/src/jquery.rsButton.js"></script>
    <script>
        $(document).ready(function () {
            $('.btn, .btnflat').rsButton();
        });
    </script>
</head>
<body>
    <button class="btn">push me</button>
    <button class="btnflat">push me</button>
    <div class="btn">push me</div>
<body>
</html>

Live demo here.

License

This project is licensed under the terms of the MIT license

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Contributing

Please refer to the Contribution page from more information.