【问题标题】:How to toggle box shadow on click with jquery如何使用 jquery 在单击时切换框阴影
【发布时间】:2017-11-04 17:03:13
【问题描述】:

我正在尝试更改单击 div 上的框阴影这是我的代码

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;
}

当鼠标点击它时,我如何使用 jquery 来切换 box-show 以将动画从完全可见变为细?

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

使用 Edwin Martin 的阴影动画 jQuery 插件,它扩展了 .animate 方法,您可以简单地使用带有“boxShadow”的常规语法以及它的各个方面——“颜色、x 和 y 偏移、模糊radius 和 spread-radius" - 动画:

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

编辑:现在包括多个阴影支持。

【讨论】:

    猜你喜欢
    • 2010-11-30
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    相关资源
    最近更新 更多