Giter Site home page Giter Site logo

huaiku / follow.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vuksamardzic/follow.js

0.0 1.0 0.0 354 KB

Small library for tracking mouse movments :comet:

Home Page: https://vuksamardzic.github.io/follow.js/

License: MIT License

JavaScript 100.00%

follow.js's Introduction

follow.js

Small library for tracking mouse movments ☄️

Demo

Includes

Before your closing <body> tag add:

<script type="text/javascript" src="./lib/follow.min.js"></script>

Usage

<div class="follow-el"></div>
<script>
    follow.init({...});
</script>

Settings

Option Type Default Description
selector string '.follow-el' CSS selector.
areas number 4 Choose how many wedges of a circle you want.
type string 'text' Choose between 'text' and 'style'
prop string '' Only required if option type is equal'style'. Css property written in camel casing. Example: backgroundColor, borderRadius, color ..
feed array [ ] Array of strings(text or css properties). feed length must be equal to number of areas.
default string '' Default value on load and when mouse is over element.

Example

<div class="follow-el"></div>
 
<script>
    //we want 3 wedges and style element's background color depending on what wedge mouse is.
    follow.init({
        areas: 3,
        type: 'style',
        prop: 'backgroundColor',
        feed: ['blue', 'red', 'green'],
        default: 'white'
    });
</script>
<div class="follow-el"></div>
 
<script>
    //we want 4 wedges and text inside element to change depending on wedge. Remember we don't need 'prop' since it's not css styling!
      follow.init({
        areas: 4,
        type: 'text',
        feed: ['one', 'two', 'three', 'four'],
        default: 'center'
    });
</script>
<div id="idSelector"></div>
 
<script>
    //we want 8 wedges and text which shows where mouse is from element perspective.
      follow.init({
        selector: '#idSelector',
        areas: 8,
        type: 'text',
        feed: ['right', 'top-right', 'top', 'top-left', 'left', 'bottom-left', 'bottom', 'bottom-right'],
        default: 'center'
    });
</script>

Now let's explain how it actually works.
exampe 1
Above we can see default setup with 4 wedges.. that is 4 wedges of element(here represented as gray circle) that follows mouse movement.
exampe 2
If we pick our type to be 'style' with prop:'backgroundColor' and give feed property array of colors it will look like picture above. In this case it's in bounds of wedge #1 so element's backgroundColor will be red.
exampe 3
If we move it to wedge #2 element's backgroundColor will be green and so forth, you get the logic.
exampe 4
Of course if we move mouse over our element it's value will be what we set in our default property. One thing to be aware is when we set how many wedges we want in areas property first wedge will always be direct right of element. We can see in next picture how it looks when we have 3 wedges (areas:3)
exampe 5
exampe 6
That's about it for type:'style', now let's explain type:'text'. In image below we can see how it would look in default state (default:'innerText').
exampe 7
Once we start moving mouse text inside element will be updated depending on wedge as we can see in following three pictures. Feed property in this case is (feed:['1st wedge','2nd wedge','3rd wedge'])
exampe 8 exampe 9 exampe 10
As we mentioned before first wedge is generated on hard right of an element as we can see in image below.
exampe 11
One more image to demonstrate how it looks when we pick choose 8 wedges (areas:8).
exampe 12

License

Licensed under the MIT license.

Made with ❤️ by Vuk Samardžić.

follow.js's People

Contributors

vuksamardzic avatar

Watchers

James Cloos avatar

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.