【问题标题】:Trigger CSS animation with checkbox inside a fieldset在字段集中使用复选框触发 CSS 动画
【发布时间】:2014-12-25 08:09:32
【问题描述】:

我尝试仅在选中复选框时触发动画。 我有以下代码:

<div data-role="fieldcontain" >
    <fieldset data-role="controlgroup" data-type="horizontal">
        <input type="checkbox" class="mediaCheckbox" id="playCheck"/>
        <label data-role="button" class="fa fa-play" id="play" for="playCheck"></label>
        <input type="checkbox" class="mediaCheckbox" id="muteCheck"/>
        <label data-role="button" class="fa fa-bell" id="mute" for="muteCheck"></label>
    </fieldset>
</div>
<div id="stuffToAnimate"></div>

以及以下 CSS:

#stuffToAnimate {
    position: relative;
    -webkit-animation: ball 11s ease-in-out 0s infinite normal; /* Chrome, Safari, Opera */
    -webkit-animation-play-state: paused;
}
#playCheck:checked **XXX**{
    -webkit-animation-play-state: running;
}

@-webkit-keyframes ball {
    0%   {top:5%;}
    40%  {-webkit-transform: rotate(0deg);}
    50%  {-webkit-transform: rotate(180deg);top:80%;}
    90%  {-webkit-transform: rotate(180deg);}
    100% {-webkit-transform: rotate(360deg);top:5%;}
}

我的问题是:如何完成**XXX** 选择器以触发动画。我可以将复选框#playCheck 放在与#stuffToAnimate 相同的级别,但这会打乱我的演示文稿。

【问题讨论】:

标签: html css animation checkbox checked


【解决方案1】:

你可以使用 jquery 给#stuffToAnimate 一个类

$('#playCheck:checkbox').click(function() {

    if ($(this).is(":checked"))
    {
        $("#stuffToAnimate").addClass("animate");
    }
    else {
        $("#stuffToAnimate").removeClass("animate");
    }
});

你的 CSS 看起来像这样

.animate{
-webkit-animation-play-state: running;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    相关资源
    最近更新 更多