树莓派相机夜视模式
If you’re anything like me, you probably use the web long after midnight, or after waking from sleep to check something on your phone. Modern LED screens put out a lot of artificial light, a technology that human perceptual systems have yet to adapt to. In particular, mobile devices pump out blue-tinted light, fooling our eyes (and thus our brains) into believing it is “day”. This suppresses melatonin levels, which in turn makes sleep more difficult.
如果您和我一样,则可能是在午夜之后或从睡眠中醒来检查手机上的东西后很长时间才使用网络。 现代的LED屏幕发出了很多人造光,人类的感知系统尚未适应这种技术。 特别是,移动设备会发出蓝色的光,使我们的眼睛(进而使我们的大脑)迷惑,以为它是“白日”。 这会抑制褪黑激素水平 ,进而使睡眠更加困难。
As modern web developers it behooves us to make our sites as adaptive as possible to the user’s environment, which includes taking into account late nights, tired eyes, and need for restful sleep. We can do this with a fairly simple alteration to our stylesheets, and a bit of JavaScript.
作为现代Web开发人员,我们应该使我们的网站尽可能适应用户的环境 ,其中包括考虑深夜,疲倦的眼睛和需要睡眠的需求。 我们可以通过对样式表进行相当简单的修改以及添加一些JavaScript来实现此目的 。
午夜之后 (After Midnight)
First, we need to determine the conditions for a night-adaptive page change. The user could be in one of several possible situations:
首先,我们需要确定适用于夜间的页面更改条件。 用户可能处于以下几种情况之一:
- Using the web after sunset, or before sunrise 日落之后或日出之前使用网络
- Trying to use their screen in a dim environment 尝试在昏暗的环境中使用他们的屏幕
- They could be photophobic (sensitive to bright light) 它们可能是憎光的(对强光敏感)
The first two we can know, or at least make educated guesses for, while cues for the latter currently have to come from the user. That means we must have both manual and automatic control over “night vision” mode.
我们可以知道前两个,或者至少可以做一些有根据的猜测,而后者的提示目前必须来自用户。 这意味着我们必须同时具有“夜视”模式的手动和自动控制 。
The simplest automatic method is to detect the local time of day, and use that to add a class to the root <html> element:
最简单的自动方法是检测一天中的本地时间,并使用该方法将一个class添加到根<html>元素 :
var currentTime = new Date().getHours(); function timeCheck() { if (currentTime > 18 || currentTime < 6) { document.documentElement.classList.add('night'); } } timeCheck();
讯享网
This script makes the semi-reasonable assumption that the sun rises at 6am and sets twelve hours later. Of course, this will change depending upon seasonality, daylight savings and the user’s location on the planet; a more thorough script would determine the user’s geolocation, and use this information to calculate the sunrise and sunset for that day.
该脚本做出半合理的假设,即太阳在凌晨6点升起并在12小时后落山。 当然,这将根据季节,夏令时和用户在地球上的位置而改变; 更全面的脚本将确定用户的地理位置 ,并使用此信息来计算当天的日出和日落。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/67411.html