网页上显示时间脚本(摘抄)

主要 HTML 标签如下:

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta name="theme-color" content="#2932e1">
    <title>时间_百度搜索</title>
</head>
<body link="#0000cc">
    <div id="wrapper" class="wrapper_l">
        <div id="wrapper_wrapper">
            <div id="container" class="container_l">
                <div id="content_left">
                    <div class="result-op c-container" srcid="11471" fk="11471_时间" id="1" tpl="beijingtime">
                        <div class="op-beijingtime">
                            <canvas class="op-beijingtime-background" width="538" height="100"></canvas>
                            <div class="op-beijingtime-box c-clearfix">
                                <p class="op-beijingtime-time">
                                    11<span>:</span>14<span class="op-beijingtime-small c-gap-left">36</span>
                                </p>
                                <p class="op-beijingtime-datebox">
                                    <span class="op-beijingtime-week">星期六</span>
                                    <span class="op-beijingtime-date">2017年6月10日</span>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

主要脚本如下:

A.merge("beijingtime", function () {
    A.setup(function () {
        var baidu = A.baidu,
            _this = this,
            getServerTime,
            drawBackground,
            drawMark,
            drawHands,
            STAR_NUM = 200,
            TIME_ZONE = 8,
            now,
            countTimeZone,
            timeZone = _this.data.timeZone || 8,
            ensureTime, bjConmunu,
            dst = _this.data.dst,
            countDayLight,
            dayLight = _this.data.dayLight,
            dayLightStatus,
            secondTimer,
            minuteTimer,
            timeFormat,
            setDateTime,
            dateSetter,
            contextFlag,
            contextEvent,
            initialize,
            initForIE,
            hourTime = 36e5,
            supportCanvas = !!document.createElement("canvas").getContext,
            $container = _this.find(".op-beijingtime"),
            bgCanvas,
            markCanvas,
            handsCanvas;

        if (
            countTimeZone = function (time, timeZone) {
                var curZone = time.getTimezoneOffset(), curDate, month, day, hour;
                if (curDate = new Date(time.getTime() + 6e4 * curZone), curDate.setTime(curDate.getTime() + timeZone * hourTime), dst) {
                    if (new Date(curDate.year, dst.month - 1, dst.day, dst.hour, 0, 0) < curDate &&
                        new Date(curDate.year, dst.endMonth - 1, dst.endDay, dst.endHour, 0, 0)) {
                        curDate.setTime(curDate.getTime() + hourTime);
                    }
                }
                return curDate
            }
            , ensureTime = function (time, timeZone) {
                var curTimezone = time.getTimezoneOffset();
                return new Date(time.getTime() + 6e4 * (time.getTimezoneOffset() - timeZone))
            }
            , getServerTime = function (callback) {
                function oncallback(jqXHR) {
                    var time = jqXHR && jqXHR.getResponseHeader("Date");
                    if (time) callback(new Date(time))
                }
                if ("function" == typeof callback) {
                    $.ajax({ url: "//www.baidu.com/nocache/fesplg/time.gif ", type: "HEAD" })
                        .done(function (data, textStatus, jqXHR) {
                            oncallback(jqXHR)
                        })
                        .fail(function (jqXHR, textStatus, errorThrown) {
                            oncallback(jqXHR)
                        })
                }
            }
            , setDateTime = function (date, time) {
                var t = time.split(":");
                return date.setHours(t[0]), date.setMinutes(t[1] || 0), date.setSeconds(t[2] || 0), date
            }
            , countDayLight = function () {
                var startTime = dayLight.start, endTime = dayLight.end;
                return startTime = setDateTime(new Date(now.getTime()), startTime),
                    endTime = setDateTime(new Date(now.getTime()), endTime),
                    startTime < now && endTime > now ? "daylight" : "night"
            }
            , drawBackground = function (isNight) {
                var ctx = bgCanvas.getContext("2d"),
                    width = bgCanvas.offsetWidth,
                    height = bgCanvas.offsetHeight,
                    grd,
                    drawStar;
                if (!dayLightStatus || dayLightStatus != isNight) {
                    if (dayLightStatus = isNight, ctx.clearRect(0, 0, width, height), drawStar = function () {
                        var i, x, y, radGrd, radius, startColor, opacity, unit;
                        for (unit = supportCanvas ? 1 : .5, i = 0; i < STAR_NUM; i++) {
                            x = Math.random() * width,
                                y = Math.random() * height,
                                radius = Math.random() + unit, opacity = radius - unit,
                                supportCanvas && (opacity /= 2),
                                radGrd = ctx.createRadialGradient(x, y, 1, x, y, radius),
                                radGrd.addColorStop(0, "rgba( 175, 175, 175, " + opacity + " )"),
                                radGrd.addColorStop(1, "rgba( 175, 175, 175, 0 )"),
                                ctx.fillStyle = radGrd,
                                ctx.beginPath(),
                                ctx.arc(x, y, radius, 0, 2 * Math.PI, true),
                                ctx.fill(),
                                ctx.closePath()
                        }
                    }, isNight) {
                        grd = ctx.createLinearGradient(0, 0, 0, height),
                            grd.addColorStop(0, "rgb(24, 50, 89)"),
                            grd.addColorStop(1, "rgb(52, 130, 186)");
                    }
                    else {
                        grd = ctx.createLinearGradient(0, 0, 0, height),
                            grd.addColorStop(0, "#0067bf"),
                            grd.addColorStop(1, "#6eabe2");
                    }
                    if (ctx.fillStyle = grd, ctx.fillRect(0, 0, width, height), isNight)
                        drawStar()
                }

            }
            , drawMark = function () {
                var ctx = markCanvas.getContext("2d"), i, lineLength, radius = markCanvas.offsetWidth / 2;
                for (ctx.translate(radius, radius), i = 0; i < 60; i++) {
                    if (ctx.lineWidth = 1, ctx.strokeStyle = "rgba( 255, 255, 255, 0.3 )", lineLength = 4, i % 5 == 0) {
                        lineLength = 8, ctx.strokeStyle = "#fff";
                    }
                    ctx.beginPath(),
                        ctx.moveTo(0, lineLength - radius),
                        ctx.lineTo(0, -radius),
                        ctx.stroke(),
                        ctx.closePath(),
                        ctx.rotate(Math.PI / 30)
                }
            }
            , drawHands = function (date) {
                var hour = date.getHours(),
                    minute = date.getMinutes(),
                    second = date.getSeconds(),
                    ctx = handsCanvas.getContext("2d"),
                    radius = handsCanvas.offsetWidth / 2,
                    draw;
                hour > 12 && (hour -= 12),
                    hour += minute / 60,
                    minute += second / 60,
                    ctx.clearRect(0, 0, 2 * radius, 2 * radius),
                    draw = function (lineWidth, strokeStyle, rotate, start, end) {
                        ctx.save(),
                            ctx.lineWidth = lineWidth,
                            ctx.strokeStyle = strokeStyle,
                            ctx.translate(radius, radius),
                            ctx.rotate(rotate),
                            ctx.beginPath(),
                            ctx.moveTo(0, start),
                            ctx.lineTo(0, end),
                            ctx.stroke(),
                            ctx.closePath(),
                            ctx.restore()
                    }
                    , draw(3, "#fff", Math.PI / 6 * hour, 6, -16),
                    draw(2, "#fff", Math.PI / 30 * minute, 6, -24),
                    draw(1, "#d93c3c", Math.PI / 30 * second, 6, -24)
            }
            , timeFormat = function (str) { return ("0" + str).slice(-2) }
            , dateSetter = {
                time: null,
                week: null,
                date: null,
                init: function () {
                    this.time = _this.find(".op-beijingtime-time")[0],
                        this.week = _this.find(".op-beijingtime-week")[0],
                        this.date = _this.find(".op-beijingtime-date")[0],
                        this.setTime(),
                        this.minuteSet()
                }
                , setTime: function () {
                    this.time.innerHTML = timeFormat(now.getHours()) + "<span>:</span>"
                        + timeFormat(now.getMinutes())
                        + ‘<span class="op-beijingtime-small c-gap-left">‘
                        + timeFormat(now.getSeconds())
                        + "</span>"
                }
                , setWeek: function () {
                    this.week.innerHTML = "星期" + "日一二三四五六".charAt(now.getDay())
                }
                , setDate: function () {
                    this.date.innerHTML = now.getFullYear() + "年" + (now.getMonth() + 1) + "月" + now.getDate() + "日"
                }
                , minuteSet: function () {
                    this.setWeek(), this.setDate()
                }
            }
            , minuteTimer = function () {
                getServerTime(function (time) {
                    now = countTimeZone(time, timeZone),
                        dateSetter.minuteSet(),
                        drawBackground("night" == countDayLight())
                }
                )
            }
            , bjConmunu = function () {
                contextFlag = true
            }
            , contextEvent = function () {
                $(document).bind("contextmenu", bjConmunu)
            }
            , initialize = function () {
                var tpl = ‘<canvas class="op-beijingtime-background" width= "#{width} " height= "100" ></canvas >                              <div class="op- beijingtime - box c- clearfix" >                                < canvas class="op- beijingtime - hands" width="65" height="65" ></canvas >                                <canvas class="op- beijingtime - mark" width="65" height="65"></canvas>                                <p class="op- beijingtime - time"></p>                                <p class="op- beijingtime - datebox">                                    <span class="op- beijingtime - week"></span>                                    <span class="op- beijingtime - date"></span>                                </p>                            </div>‘;
                if ($container.html($.format(tpl, { width: _this.container.offsetWidth })),
                    bgCanvas = _this.find(".op-beijingtime-background")[0],
                    markCanvas = _this.find(".op-beijingtime-mark")[0],
                    handsCanvas = _this.find(".op-beijingtime-hands")[0],
                    !supportCanvas) {
                    A.ui.canvas.init([bgCanvas, markCanvas, handsCanvas]);
                }
                $(document).ready(function () {
                    getServerTime(function (time) {
                        now = time, contextEvent(),
                            now = countTimeZone(now, timeZone),
                            drawBackground("night" == countDayLight()),
                            drawMark(),
                            drawHands(now),
                            dateSetter.init(),
                            secondTimer = window.setInterval(function () {
                                var timeObj, timezone;
                                if (0 == now.getSeconds() || true == contextFlag)
                                    minuteTimer(), contextFlag = false;
                                if (timezone = now.getTimezoneOffset(), now = new Date(now.getTime() + 1e3), now.getTimezoneOffset() != timezone) {
                                    now = ensureTime(now, timezone);
                                }
                                drawHands(now), dateSetter.setTime()
                            }, 1e3)
                    })
                })
            }
            , supportCanvas) {
            initialize();
        }
        else {
            A.use("canvas", function () { initialize() });
        }
        this.dispose = function () {
            window.clearInterval(secondTimer), $(document).unbind("contextmenu", bjConmunu)
        }
    });
});
时间: 2025-01-01 13:54:33

网页上显示时间脚本(摘抄)的相关文章

图片的base64编码实现以及网页上显示

生成.解析base64编码的图片 //图片转化成base64字符串 public static String GetImageStr(<span style="font-family: Arial, Helvetica, sans-serif;">String imgFile</span><span style="font-family: Arial, Helvetica, sans-serif;">) </span>

word和excel在网页上显示,文件流,虚拟目录,文件上传

1.如何在网页上显示word和excel a.可以使用aspose将word 和excel 转换为pdf 然后在网页上打开pdf,但是效果不是很好.比如说excel 多个工作薄不是按exce 格式显示出来,宽度大小,不好控制(?). b.可以使用aspose将文档转换为html,但是转换为html 会产生额外的XML和CSS和图片文件.在文件流中不好读取(文件在本地里面). c.可以使用其他转换,比如http://www.cutepdf.com/(?),或者用文件流读取再转换(没试过),或者是w

winform中的状态栏,以及在状态栏目上显示时间

1:在winform上添加状态栏,并且在状态栏目上多添加几个label. step1:拖一个StatusStrip到winform上,名字默认为statusStrip1.找到statusStrip1的items属性,双击打开添加3个StatusLabel.名字默认分别为toolStripStatusLabel1.toolStripStatusLabel2.toolStripStatusLabel3.他们分别是从左到右显示.设置toolStripStatusLabel2的属性的BorderSide

jupyter notebook在网页上显示作图

今天尝试使用jupyter notebook作图像展示工具时,发现用matplotlib所作的图像会自动启动一个图像展示窗口,无法显示在网页上,而我的初衷是使用jupyter notebook做图像即时呈现及存储(有点类似PPT作图). 随机生成一批正弦数据: import numpy as np import matplotlib.pyplot as plt x=np.arange(10) y=np.sin(x) plt.plot(x,y) plt.show() 使用%matplotlib命令

网页上显示数学公式目前哪种方案最好? 来自知乎

作者:Hello World链接:http://www.zhihu.com/question/26798550/answer/34064562来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 应该是MathJax吧,至少算得上是使用最广泛的,很多知名的网站像arXiv, MathSciNet, Science Direct, APS Journals, MathOverflow, Physics StackExchange, Scholarpedia等都在用 优点是

&lt;body&gt;标签,网页上显示的内容放在这里

在网页上要展示出来的页面内容一定要放在body标签中.如下图是一个新闻文章的网页. 在浏览器中的显示效果: 示例: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>了不起的盖茨比</title> </head> <bo

解决apache上访问 cgi脚本时总是在网页中显示出脚本的源代码而不是执行结果的问题

apache是支持cgi脚本的,但是需要保证四个条件: 1.放置cgi脚本的文件夹本身需要对apache服务器这个用户(一般默认用户名是www,linux下的用户机制请自行百度)开放x(即可执行)权限. 2.这个脚本本身必须对apache服务器这个用户开放x权限 3.脚本的首行附有如何使用什么解释器执行该脚本代码的信息 如python脚本首行 #!/usr/bin/env python 4.apache需加载了mod_cgi.so这一动态链接库 最后这个问题不是经常遇到但由于容易被忽略所以常常是

在状态栏上显示时间

// TODO: 在此添加消息处理程序代码和/或调用默认值 //获得当前的系统时间 CTime t=CTime::GetCurrentTime();                         CClientDC dc(this); //格式可以参考MSDN中的strftime函数 CString str=_T("时间:")+ t.Format("%Y-%m-%d %H:%M:%S"); //设置一个CClientDC对象来获取str的长度      CSize

[2016-02-09][javascript][在网页上显示内容]

通过调用 document.write(string); 来表示内容 string 为 html网页中的内容 如: 1 2 3 4 5 6 <script type="text/javascript">     var test = parseInt("as123");     document.write(test);     document.write("</br>");     document.write(666