Giter Site home page Giter Site logo

sarathsaleem / grained Goto Github PK

View Code? Open in Web Editor NEW
267.0 10.0 52.0 1.45 MB

Generate animated noise texture with grained.js

Home Page: http://sarathsaleem.github.io/grained/

License: MIT License

JavaScript 100.00%
grains animation javascript texture

grained's Introduction

Add animated grain texture effect to your content.

With grained.js you can add customized noise effect on your web page. It has easily customizable options to generate the animated noise effect. The animation is added using CSS3 key-frame animation and instantly generated png noise image.

"Create your own"

Create your own

How to use

Include the library file in your html page.

<script src="grained.js"></script>

initialize the library by

grained('elementId',options)

'elementId' is the id of the container element to add the grain effect. It is important to note that grainedjs will not change the background of the container element. It appends a div element as the first child of the container. Grainedjs will add two style changes to the container element 'position:relative;overflow:hidden'. If the container position is absolute it will remand as absolute only.

Since a 'div' element with class 'grained' is added as first child element with position absolute it will have the z index priority and appears on top of other contents in the container element. If you want the other elements in container element on top of grained effect you have to add a css like

#container > * { position:relative; }

So the ideal structure of implementaion is like follows

<div id="container">
   <div class="contents">
     your contents goes here .. like <a>, <p> etc
   </div>
</div>

after initilizing grained('#container', {}); it will look like this

<div id="container">
    <div class='grained'></div>
    <div class="contents">
        your contents goes here .. like <a>, <p> etc
    </div>
</div>

Options

With these options you can crate customized grained effect , these are the option parameter you can change and the default values.

 var options = {
         animate: true,
         patternWidth: 100,
         patternHeight: 100,
         grainOpacity: 0.05,
         grainDensity: 1,
         grainWidth: 1,
         grainHeight: 1
 };

With animation true/false you can create textures with grain movement and a static one. The other value you can see the live in online generator

grained's People

Contributors

anirudh-eka avatar lpmi-13 avatar saadbazaz avatar sarathsaleem 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

grained's Issues

"Download texture as png" not working

Hello.

Love your work here! I have one small issue. Trying to create a website on Tilda.cc I am not sure I can even add any java libraries so I was trying to download the .PNG for the project. Somehow 2 different browsers won't work. Is there maybe an issue with the button?

Working example ?

Hey! I tried to implement this on a website I am trying to build. I want to generate a grain-animation in the entire background of the website. But, I am unable to get it working

Perhaps you could setup a working example, that I could use?

Mouse input broken once grained.js is added

Added grained.js to my website with the following code:

<script src="https://cdn.rawgit.com/sarathsaleem/grained/master/grained.js"></script>

<script>
var options = {
  "animate": true,
  "patternWidth": 600,
  "patternHeight": 600,
  "grainOpacity": 0.15,
  "grainDensity": 1,
  "grainWidth": 0.7,
  "grainHeight": 0.7,
}
grained("#hero", options);

/*
background-color :rgb(204, 204, 204)
*/
</script>

For some reason, custom cursor and links all broke.... Anyone else had this issue?

How to use this with nextjs?

I am not able to use this in nextjs, everytime i import it in a class and try to call it in componentDidMount(), the import throws an error called window not defined

and when i try dynamic importing like this

const grained = dynamic(
    () => {
      return import ('../../grained.min.js');
    },
    { ssr: false }
  );

and call it in componentdidmount like this

componentDidMount(){
        grained('#container', {});
    }

i get an error, cannot call a class as a function

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.