1

i am trying to change the box shadow on the click on the div here is my code

index.html

<html>
    <head>

        <script src="jquery-3.2.1.min.js"></script>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="ttt"></div>
        <script src="script.js"></script>
    </body>
</html>

script.js

$(document).ready(function () {
    var state = false;
    $("#ttt").click(function () {
        if (state) {
            $("#ttt").animate({
                'boxShadowX': '10px',
                'boxShadowY': '10px',
                'boxShadowBlur': '20px'
            });
        } else {
            $("#ttt").animate({
                'boxShadowX': '3px',
                'boxShadowY': '3px',
                'boxShadowBlur': '3px'
            });
        }
        console.log(state);
        state = !state;
    });

});

style.css

#ttt{
    padding-left: 100px;
    padding-top: 100px;
    padding-right: 100px;
    padding-bottom: 100px;
    width: 100px;
    height: 100px;
    background-color: red;
    border-radius: 10px;
    box-shadow: 10px 10px 5px #888888;
}

how can i use jquery to toggle the box-show to animate from fully visible to thin when the mouse is clicked on it ?

Nijeesh Joshy
  • 1,426
  • 13
  • 24

1 Answers1

0

Using Edwin Martin's jQuery plugin for shadow animation, which extends the .animate method, you can simply use the normal syntax with "boxShadow" and every facet of that - "color, the x- and y-offset, the blur-radius and spread-radius" - gets animated:

$(selector).animate({ boxShadow : "0 0 5px 3px rgba(100,100,200,0.4)" }); 

Edit: Now includes multiple shadow support.

Nijeesh Joshy
  • 1,426
  • 13
  • 24