Lightweight JavaScript library that allows you add motion blur to your CSS animations

Overview

MotionBlurJS

For more information and examples please visit: https://www.motionblurjs.com

What is MotionBlurJS

MotionBlurJS is a lightweight JavaScript library that allows your animations to shine with homemade native CSS Motion Blur and Motion Fade while keeping your code clean and your CSS animations smooth.

The simple method

You can use MotionBlurJS by simply linking to it in your document head tag like so:

<head>
    <script src="https://www.motionblurjs.com/blur.js"></script>
</head>

After that, all you have to do is naming the class of the div you want to blur to either the blurjs or fadejs class, you can mix it with your current classes as well by separating those with spaces, like so:

<div id="yourId" class="someClass blurjs"></div>

or

<div id="yourId" class="fadejs someClass"></div> 

Maintatining opacity with fadejs

If your elements require opacity (alpha channel), you can achieve that with fadejs by adding the fadejs-data property to your animated elements, like so:

<div id="yourId" class="fadejs someClass" fadejs-data="opacity: 0.6;"></div> 

Note that in this example the opacity will be 60% but the syntax is between 0-1 (like CSS).

The dynamic method

The dynamic method requires the same script linking as the simple method shown above.
This method will allow you to dynamically blur the objects even if they won’t load with the page itself, to achieve this just add this img tag inside the div you want to blur, like so:

<div id="yourId" class="someClass">
    <img src="" onerror="blurMe(event);" style="display:none !important;" />
</div>

or

<div id="yourId" class="someClass">
    <img src="" onerror="fadeMe(event);" style="display:none !important;" />
</div>

The SVG method

This method can add motion blur to SVG elements and .SVG files, by simply linking to it first thing inside the svg tag, like so:

<svg ...>
    <script xlink:href="https://www.motionblurjs.com/blurSVG.js" />

After that, all you have to do is naming the class of the element you want to blur to either the blurjs or fadejs class, you can mix it with your current classes as well by separating those with spaces, like so:

<circle id="yourId" class="st0 blurjs" cx="200" cy="200" r="42" />

or

<circle id="yourId" class="st0 fadejs" cx="200" cy="200" r="42" />

How does it work

MotionBlurJS will duplicate your objects so they can get blurred or faded on runtime, the DOM will only show the necessary objects (no pesky img tags) in order for it to work properly the blurred object has to be positioned absolutely and to be animated with CSS animation.

Bug report

This code is under active development, if you experience any bugs or kinks, feel free to report those through Github or by mail: [email protected] please mention which method you were using and if possible, send me your code snippets,
Happy coding !

You might also like...

A tiny JavaScript library to enable CSS animations when user scrolls.

A tiny JavaScript library to enable CSS animations when user scrolls.

A tiny JavaScript library to enable CSS animations when user scrolls. This library allows you to toggle one or more classes on an element when it appe

Nov 24, 2022

Awesome book with ES6, this project is build using HTML,CSS, JavaScript ES6 the project allows you to add books and save them with the author , for another time checks

Project Name Awsome books Description the project. adding books daynamiclly Built With Major languages Frameworks Technologies used Live Demo (if avai

Jul 25, 2022

A library management system that built with JavaScript, HTML, and CSS. Allows the user to add new books and delete books.

Awesome books: with ES6 in this project: Set up the linters for html, css, and JavaScript. Create a popup window for desktop and mobile. Built With Ht

Dec 18, 2022

This is a project that allows users to add/remove books from a list. we accomplish this by using a JavaScript object. Built with JavaScript, Html and CSS.

Awesome-book This is a project that allows users to add/remove book from a list. we accomplish this by usig javascript oject. Built With HTML5 CSS3 Ja

May 27, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. Made with webpack, JavaScript ES6 , HTML 5 and CSS 3.

Hello! I am a software developer! I can help you build a product, feature or website. Take a look of my works. If you like what you see and have a pro

Jul 17, 2022

To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. Made with webpack, JavaScript ES6 , HTML 5 and CSS 3.

Microverse Webpack Javascript For the second Javascript milestone in building a todo website, set up a new repository and prepare it for development u

Jun 13, 2022

This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Oct 3, 2022
Comments
  • Functionality to allow for FadeJs rendering to have a maximum opacity setting

    Functionality to allow for FadeJs rendering to have a maximum opacity setting

    Hello, Adir-SL, I hope this Pull Request finds you well 😄

    I recently came across your module here, and thought it was really cool! However, it wasn't working with my project, as I wanted to use it on elements that had various opacity levels. Thus, I have solved the problem by adding optional functionality for setting the maximum opacity used by the fadejs rendering.

    Problem:

    Currently, when using the "fadejs" rendering, if the target element also has a stylesheet class that sets it's opacity below 100%, the fadejs rendering will make the element appear as if it were set to 100%.

    Solution:

    I Added logic that can extract a custom html tag attribute, "fadejs-data", that a page can use to define an element's maximum opacity. Then, the algorithm in place will allow the cascaded fadejs rendered element's opacity to match the intended opacity for the element, while still having the same effect, to scale.

    The algorithm used is a branching algorithm containing several polynomials generated via Lagrange Interpolation after taking precise measurements by the thousandth decimal place for the "correct value", after using a baseline formula for all 4 rendered fadejs elements: [f(x) = x / 1.805555555, f2(x) = .75f(x), f3(x) = .5f(x), f4(x) = .25f(x)].

    Usage:

    The attribute is added to a tag like so (a leading 0 is required, but the semicolon and space is not):

    <div id="someDivElement" class="fadejs someOtherStyle" fadejs-data="opacity: 0.65;"/>
    

    It uses a value of 1 by default (if the attribute is missing from the tag or the value exceeds 1), which will emulate the same behavior as fadejs currently has (making this feature optional and non-breaking).

    Impact:

    I have not benchmarked performance at all. I would imagine it's very minimal. I used a branching algorithm to make this calculation as efficient as possible. Obviously this increases the file size of the *.js file quite a bit, relatively.. Perhaps a minified *.js could be provided to negate the impact in terms of file-size.

    A Note on Opacity Animations:

    One other important thing to note: When the fadejs class is used, even with a maximum opacity set, any CSS "from-to" keyframe animations involving setting the opacity will still not work as intended, and will have a severe flicker effect. However, a working solution is to do something like this:

    Assume that 0.65 is my intended opacity. First, I get the "maximum" opacity of the animation as 0.1875. I get this using this formula: y = (x + 0.1) / 4. Next, you set the animation to cap out at 25%. Then, you increase the speed of your animation using the formula: y = 12x . So, in this instance, I initially wanted the animation to fade from 0 - .65 opacity in .5s. Using the following combination of keyframe animations will accomplish this, with the Fadejs effect on the transform animation!!

    .myAnimationClass {
    	visibility: hidden;
    
    	transition: all 0.5s ease !important;
    	animation:  0.5s ease 0.25s 1 slideIn, 6s 0s 1 fadeIn;
    	animation-fill-mode: forwards;
    }
    
    @keyframes slideIn {
    	from { transform: translateX(250px); }
    	to { transform: translateX(0); }
    }
    
    @keyframes fadeIn {
    	0% {
    	  opacity: 0;
    	  visibility: visible;
    	}
    	25% {
    	  opacity: 0.1875;
    	}
    	100% {
    	  visibility: visible;
    	}
    }
    

    Voilà!

    opened by xSlither 1
Owner
Adir
Adir
Quick and easy spring animation. Works with other animation libraries (gsap, animejs, framer motion, motion one, @okikio/animate, etc...) or the Web Animation API (WAAPI).

spring-easing NPM | Github | Docs | Licence Quick and easy spring animations. Works with other animation libraries (gsap, animejs, @okikio/animate, mo

Okiki Ojo 34 Dec 14, 2022
Lightweight and easy to use vanilla js library to add css animations to elements on scroll.

Scrollrisen Trigger css animations on scroll as elements enter the viewport. Zero dependencies, lightweight and easy to use and customize Installation

null 1 Oct 13, 2022
Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components.

Chakra UI Animations Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components. Installation yarn add @

Code Chemistry Inc. 9 Nov 19, 2022
"Awesome books" is a simple website that displays a list of books and allows you to add ang remove books from that list. Also you can store your data in your local storage. Build with JavaScript, HTML and CSS.

Awesome Books Creating an app that adds and delete books from a list. Built With HTML CSS JavaScript Application Page url https://TimmyChan99.github.i

Fatima Ezzahra elmenoun 5 Jan 28, 2022
Cindy Dorantes 12 Oct 18, 2022
Emem Ekpo 7 Sep 9, 2022
To do list is a simple CRUD application that allows you to add, delete, update tasks that you are supposed to do. It is built with HTML, CSS and JavaScript

to do List To do list is a simple CRUD application that allows you to add, delete, update tasks that you are supposed to do. Built With HTML-5 CSS3 Ja

Lynette Acholah 11 Jun 7, 2022
Careers page made with Next.js, Framer Motion & Tailwind CSS

Careers Page Tech Stack: Next.js / Framer Motion / Tailwind CSS This is a Next.js project bootstrapped with create-next-app. Getting Started First, ru

Jack Latimer 7 Nov 16, 2022
Small example showing how you can make game sprite animations using CSS with Javascript movement.

Hi there, I'm Björn Hjorth ?? I like combining the web and game development, if you like what you see please do not be a stranger and say "Hi" on Twit

Björn Hjorth 29 Nov 9, 2022