Giter Club home page Giter Club logo

boxshadowrotate's Introduction

rotateBoxShadow

Automatically adjust the CSS box-shadow to keep it in the same place regardless of an element's rotation.

You set the box shadow as you would like it to appear if the element were not rotated. e.g.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body {
            padding: 20%;
        }
        .item {
            box-shadow: 0 20px 10px -3px rgba(0,0,0, 0.5);
            transform: rotate(33deg);
            display: inline-block;
            border: 1px solid red;
            padding: 0.5em;
        }
    </style>
</head>
<body>
    <div class="item">This is rotated, but box shadow is always below</div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="dist/rotatedBoxShadow.jquery.min.js"></script>
    <script>
        $(document).ready(function() {
            $('.item').rotateBoxShadow();
        });
    </script>
</body>
</html>

Use without jQuery

Include the file dist/rotatedBoxShadow.min.js, and use the object interface.

var rotated = new RotatedBoxShadow(document.querySelector('.item'));

The object interface has methods to force reparsing the CSS if, for example, your box shadow CSS has change and you want to adjust a new box shadow.

These methods are also available as jquery plugin actions: (e.g. $('.item').rotatedBoxShadow('reloadCSS'); )

rotated.reloadCSS();

You can also manually re-apply the box shadow rotation as needed.

rotated.apply();

Mutation Listener

By default this class listens for changes to the element's style or class attributes and re-adjusts the box shadow if the rotation has changed.

boxshadowrotate's People

Contributors

lingo avatar

Watchers

 avatar  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.