如何为AngularJS Application定义两种模式(夜/日)

时间:2016-08-17 13:18:36

标签: javascript css angularjs sass angular-ui-router

我正在使用Angularjs处理应用程序。我对一个问题动画感到震惊 我想在我的应用程序中添加以两种模式(夜晚和白天模式)显示的方式。我看到每次更改模式时我都可以使用主题提供程序来更改主题。但还有其他解决方案吗?例如,使用级联样式表以及如何使用它 任何人都可以帮助我,并建议最好的方法来做这个解决方案。
感谢

1 个答案:

答案 0 :(得分:4)

您需要的是根据日/夜情况在 body 元素上切换css类。

<body ng-class="{'night-mode': isNight()}">
    <div>
        <p>Some</p>
        <p>content</p>
        <p>Inside</p>
    </div>
</body>

在css中,您可以定义默认主题和夜间选择:

body div {
    background-color: gray;
}

body.night-mode div {
    background-color: blue;
}

内部angularjs控制器定义功能检查夜间模式条件:

function controller($scope) {
    $scope.isNight = function() {
        var hours = new Date().getHours();
        return hours > 19 || hours < 8;
    };    
}

这是一个当然的例子;)