普陀申木 发表于 2024-11-2 08:09

沙发挂钟可做背景图片

本帖最后由 普陀申木 于 2024-11-2 08:28 编辑 <br /><br /><style>
        #papa {

        margin: 30px 0 30px calc(50% - 641px);
        width: 1280px;
        height: 720px;
        background: url('https://pic.imgdb.cn/item/6724ca4bd29ded1a8c7e3ee5.jpg') no-repeat center/cover;

        overflow: hidden;
        z-index: 1;
        position: relative;
}

        #hHand, #mHand, #sHand { animation: turning var(--dur) linear infinite; }
        #hHand { --begin: 0deg; --dur: 216000s; }
        #mHand { --begin: 0deg; --dur: 3600s; }
        #sHand { --begin: 0deg; --dur: 60s; }
        #kedu { font: normal 16px Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; text-anchor: middle; dominant-baseline: middle; fill: transparent; user-select: none; }
        @keyframes turning { from { transform: rotate(var(--begin)); } to { transform: rotate(calc(360deg + var(--begin))); } }
.ipic { position: absolute; bottom: 0; transform: skew(-3deg);transform-origin: 0% 0%;}
        .ipic:nth-of-type(1) { left: 708px; bottom: 255px; animation: skew1 3s infinite linear ;width: 400px; height: 410px;}
       
       
        .stop .ipic:nth-of-type(1){animation-play-state: paused;}
       
        @keyframes skew1 { 50%{ transform: skew(3deg); } }
       

        </style>

<div id="papa">
        <svg id="clock" width="1280" height="263" viewBox="-1272 -220 650 650">
                <defs>
                        <linearGradient id="bg" x1="0" x2="1" y1="0" y2="1">
                                </linearGradient>
                </defs>
                <circle cx="0" cy="0" r="85" fill="transparent" stroke="" stroke-width="10" />
                <g id="kedu">
                        <text font-size="14" fill=" " text-anchor="middle">
                                <tspan id="tdate" x="5" y="-35">日期</tspan>
                                <tspan id="tday" x="0" y="-15">星期</tspan>
                                <tspan x="0" y="40" fill="">石英钟</tspan>
                        </text>
                </g>
                <line id="hHand" x1="0" y1="0" x2="0" y2="-65" stroke="Black " stroke-width="4" />
                <line id="mHand" x1="0" y1="0" x2="0" y2="-75" stroke="Black " stroke-width="3" />
                <line id="sHand" x1="0" y1="0" x2="0" y2="-85" stroke="Black " stroke-width="2" />
                <circle cx="0" cy="0" r="6" fill="red" stroke="white" stroke-width="2" />
        </svg>
        <div id="testImg">
        <img class="ipic" src="https://pic.imgdb.cn/item/6724ca4bd29ded1a8c7e3ef4.png" alt="" />


</div>

<script>
setAttr = (elm, objData) => {
        for(var key in objData) {
                elm.setAttribute(key, objData);
        }
};

mkScale = (total=60) => {
        var deg = 360 / total;
        Array(total).fill('').forEach((l,k) => {
                var w = -6;
                if(k % 5 === 0) {
                        var t = document.createElementNS('http://www.w3.org/2000/svg', 'text');
                        setAttr(t, {transform: `rotate(${deg * k - 60} 0 0) translate(75) rotate(${-1 * (deg * k - 60)} 0 0)`});
                        t.textContent = k / 5 + 1;
                        kedu.appendChild(t);
                        w = -4;
                }
                l = document.createElementNS('http://www.w3.org/2000/svg', 'line');
                setAttr(l, {transform: `rotate(${deg * k - 60} 0 0) translate(90)`, x1: 0, y1: 0, x2: w, y2: 0, stroke: 'cyan'});
                kedu.appendChild(l);
        });
};

setTime = () => {
        var now = new Date();
        var hr = now.getHours() > 12 ? now.getHours() - 12 : now.getHours(),
                min = now.getMinutes(),
                sec = now.getSeconds(),
                msec = now.getMilliseconds();
        var hDeg = hr * 30 + (min * 6 / 12),
                mDeg = min * 6 + (sec * 6 / 60),
                sDeg = sec * 6 + (msec * 0.36 / 1000);
        hHand.style.setProperty('--begin', hDeg + 'deg');
        mHand.style.setProperty('--begin', mDeg + 'deg');
        sHand.style.setProperty('--begin', sDeg + 'deg');
};

setDate = () => {
        var sDate = new Date();
        var sDateS = sDate.getSeconds() * 1000,
                sDateMs = sDate.getMilliseconds();
        tdate.textContent = `${sDate.getFullYear()}年${sDate.getMonth() + 1}月${sDate.getDate()}日`;
        tday.textContent = `星期${'日一二三四五六'.substr(sDate.getDay(),1)}`;
        setTimeout( () => {
                setDate();
        }, 60000 - sDateS - sDateMs);
};

mkScale();
setTime();
setDate();
</script>
        </div>

普陀申木 发表于 2024-11-2 08:18

本帖最后由 普陀申木 于 2024-11-2 08:30 编辑 <br /><br /><style>
        #papa {

        MARGIN-LEFT:100px;margin-top: 30px;
        width: 297px;
        height: 287px;
        background: url('https://pic.imgdb.cn/item/6714807cd29ded1a8c1e6f2d.png') no-repeat center/cover;
       
        overflow: hidden;
        z-index: 1;
        position: relative;
}

        #hHand, #mHand, #sHand { animation: turning var(--dur) linear infinite; }
        #hHand { --begin: 0deg; --dur: 216000s; }
        #mHand { --begin: 0deg; --dur: 3600s; }
        #sHand { --begin: 0deg; --dur: 60s; }
        #kedu { font: normal 16px Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; text-anchor: middle; dominant-baseline: middle; fill: transparent; user-select: none; }
        @keyframes turning { from { transform: rotate(var(--begin)); } to { transform: rotate(calc(360deg + var(--begin))); } }
</style>

<div id="papa">
        <svg id="clock" width="396" height="392" viewBox="-183 -155 450 450">
                <defs>
                        <linearGradient id="bg" x1="0" x2="1" y1="0" y2="1">
                               
                        </linearGradient>
                </defs>
                <circle cx="0" cy="0" r="85" fill="transparent" stroke="url(#bg)" stroke-width="10" />
                <g id="kedu">
                        <text font-size="14" fill="silver" text-anchor="middle">
                                <tspan id="tdate" x="5" y="-35">日期</tspan>
                                <tspan id="tday" x="0" y="-15">星期</tspan>
                                <tspan x="0" y="40" fill="gray">石英钟</tspan>
                        </text>
                </g>
                <line id="hHand" x1="0" y1="0" x2="0" y2="-65" stroke="whitesmoke" stroke-width="4" />
                <line id="mHand" x1="0" y1="0" x2="0" y2="-75" stroke="snow" stroke-width="3" />
                <line id="sHand" x1="0" y1="0" x2="0" y2="-85" stroke="white" stroke-width="2" />
                <circle cx="0" cy="0" r="6" fill="red" stroke="white" stroke-width="2" />
        </svg>
</div>

<script>
setAttr = (elm, objData) => {
        for(var key in objData) {
                elm.setAttribute(key, objData);
        }
};

mkScale = (total=60) => {
        var deg = 360 / total;
        Array(total).fill('').forEach((l,k) => {
                var w = -6;
                if(k % 5 === 0) {
                        var t = document.createElementNS('http://www.w3.org/2000/svg', 'text');
                        setAttr(t, {transform: `rotate(${deg * k - 60} 0 0) translate(75) rotate(${-1 * (deg * k - 60)} 0 0)`});
                        t.textContent = k / 5 + 1;
                        kedu.appendChild(t);
                        w = -4;
                }
                l = document.createElementNS('http://www.w3.org/2000/svg', 'line');
                setAttr(l, {transform: `rotate(${deg * k - 60} 0 0) translate(90)`, x1: 0, y1: 0, x2: w, y2: 0, stroke: 'cyan'});
                kedu.appendChild(l);
        });
};

setTime = () => {
        var now = new Date();
        var hr = now.getHours() > 12 ? now.getHours() - 12 : now.getHours(),
                min = now.getMinutes(),
                sec = now.getSeconds(),
                msec = now.getMilliseconds();
        var hDeg = hr * 30 + (min * 6 / 12),
                mDeg = min * 6 + (sec * 6 / 60),
                sDeg = sec * 6 + (msec * 0.36 / 1000);
        hHand.style.setProperty('--begin', hDeg + 'deg');
        mHand.style.setProperty('--begin', mDeg + 'deg');
        sHand.style.setProperty('--begin', sDeg + 'deg');
};

setDate = () => {
        var sDate = new Date();
        var sDateS = sDate.getSeconds() * 1000,
                sDateMs = sDate.getMilliseconds();
        tdate.textContent = `${sDate.getFullYear()}年${sDate.getMonth() + 1}月${sDate.getDate()}日`;
        tday.textContent = `星期${'日一二三四五六'.substr(sDate.getDay(),1)}`;
        setTimeout( () => {
                setDate();
        }, 60000 - sDateS - sDateMs);
};

mkScale();
setTime();
setDate();
</script>

梦江南 发表于 2024-11-2 08:23

普陀申木 发表于 2024-11-2 08:18
#papa {margin:

        MARGIN-LEFT:100px;margin-top: 30px;


欣赏老师挂钟佳作。

普陀申木 发表于 2024-11-2 08:32

&lt;style&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; #papa {margin: 30px 0 30px calc(50% - 641px);<br>&nbsp; &nbsp; &nbsp; &nbsp; width: 1280px;<br>&nbsp; &nbsp; &nbsp; &nbsp; height: 720px;<br>&nbsp; &nbsp; &nbsp; &nbsp; background: url('https://pic.imgdb.cn/item/6724ca4bd29ded1a8c7e3ee5.jpg') no-repeat center/cover;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; overflow: hidden;<br>&nbsp; &nbsp; &nbsp; &nbsp; z-index: 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; position: relative;<br>}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; #hHand, #mHand, #sHand { animation: turning var(--dur) linear infinite; }<br>&nbsp; &nbsp; &nbsp; &nbsp; #hHand { --begin: 0deg; --dur: 216000s; }<br>&nbsp; &nbsp; &nbsp; &nbsp; #mHand { --begin: 0deg; --dur: 3600s; }<br>&nbsp; &nbsp; &nbsp; &nbsp; #sHand { --begin: 0deg; --dur: 60s; }<br>&nbsp; &nbsp; &nbsp; &nbsp; #kedu { font: normal 16px Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; text-anchor: middle; dominant-baseline: middle; fill: transparent; user-select: none; }<br>&nbsp; &nbsp; &nbsp; &nbsp; @keyframes turning { from { transform: rotate(var(--begin)); } to { transform: rotate(calc(360deg + var(--begin))); } }<br>.ipic { position: absolute; bottom: 0; transform: skew(-3deg);transform-origin: 0% 0%;}<br>&nbsp; &nbsp; &nbsp; &nbsp; .ipic:nth-of-type(1) { left: 708px; bottom: 255px; animation: skew1 3s infinite linear ;width: 400px; height: 410px;}<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; .stop .ipic:nth-of-type(1){animation-play-state: paused;}<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; @keyframes skew1 { 50%{ transform: skew(3deg); } }<br>&nbsp; &nbsp; &nbsp; &nbsp; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/style&gt;<br> <br>&lt;div id="papa"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;svg id="clock" width="1280" height="263" viewBox="-1272 -220 650 650"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;defs&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;linearGradient id="bg" x1="0" x2="1" y1="0" y2="1"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/linearGradient&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/defs&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;circle cx="0" cy="0" r="85" fill="transparent" stroke="" stroke-width="10" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;g id="kedu"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;text font-size="14" fill=" " text-anchor="middle"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tspan id="tdate" x="5" y="-35"&gt;日期&lt;/tspan&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tspan id="tday" x="0" y="-15"&gt;星期&lt;/tspan&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tspan x="0" y="40" fill=""&gt;石英钟&lt;/tspan&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/text&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/g&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line id="hHand" x1="0" y1="0" x2="0" y2="-65" stroke="Black " stroke-width="4" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line id="mHand" x1="0" y1="0" x2="0" y2="-75" stroke="Black " stroke-width="3" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;line id="sHand" x1="0" y1="0" x2="0" y2="-85" stroke="Black " stroke-width="2" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;circle cx="0" cy="0" r="6" fill="red" stroke="white" stroke-width="2" /&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/svg&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div id="testImg"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;img class="ipic" src="https://pic.imgdb.cn/item/6724ca4bd29ded1a8c7e3ef4.png" alt="" /&gt;<br><br><br>&lt;/div&gt;<br> <br>&lt;script&gt;<br>setAttr = (elm, objData) =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; for(var key in objData) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elm.setAttribute(key, objData);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>};<br> <br>mkScale = (total=60) =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; var deg = 360 / total;<br>&nbsp; &nbsp; &nbsp; &nbsp; Array(total).fill('').forEach((l,k) =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var w = -6;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(k % 5 === 0) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var t = document.createElementNS('http://www.w3.org/2000/svg', 'text');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttr(t, {transform: `rotate(${deg * k - 60} 0 0) translate(75) rotate(${-1 * (deg * k - 60)} 0 0)`});<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.textContent = k / 5 + 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kedu.appendChild(t);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = -4;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; l = document.createElementNS('http://www.w3.org/2000/svg', 'line');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setAttr(l, {transform: `rotate(${deg * k - 60} 0 0) translate(90)`, x1: 0, y1: 0, x2: w, y2: 0, stroke: 'cyan'});<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kedu.appendChild(l);<br>&nbsp; &nbsp; &nbsp; &nbsp; });<br>};<br> <br>setTime = () =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; var now = new Date();<br>&nbsp; &nbsp; &nbsp; &nbsp; var hr = now.getHours() &gt; 12 ? now.getHours() - 12 : now.getHours(),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min = now.getMinutes(),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sec = now.getSeconds(),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; msec = now.getMilliseconds();<br>&nbsp; &nbsp; &nbsp; &nbsp; var hDeg = hr * 30 + (min * 6 / 12),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mDeg = min * 6 + (sec * 6 / 60),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sDeg = sec * 6 + (msec * 0.36 / 1000);<br>&nbsp; &nbsp; &nbsp; &nbsp; hHand.style.setProperty('--begin', hDeg + 'deg');<br>&nbsp; &nbsp; &nbsp; &nbsp; mHand.style.setProperty('--begin', mDeg + 'deg');<br>&nbsp; &nbsp; &nbsp; &nbsp; sHand.style.setProperty('--begin', sDeg + 'deg');<br>};<br> <br>setDate = () =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; var sDate = new Date();<br>&nbsp; &nbsp; &nbsp; &nbsp; var sDateS = sDate.getSeconds() * 1000,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sDateMs = sDate.getMilliseconds();<br>&nbsp; &nbsp; &nbsp; &nbsp; tdate.textContent = `${sDate.getFullYear()}年${sDate.getMonth() + 1}月${sDate.getDate()}日`;<br>&nbsp; &nbsp; &nbsp; &nbsp; tday.textContent = `星期${'日一二三四五六'.substr(sDate.getDay(),1)}`;<br>&nbsp; &nbsp; &nbsp; &nbsp; setTimeout( () =&gt; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setDate();<br>&nbsp; &nbsp; &nbsp; &nbsp; }, 60000 - sDateS - sDateMs);<br>};<br> <br>mkScale();<br>setTime();<br>setDate();<br>&lt;/script&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br>

红影 发表于 2024-11-2 09:45

漂亮的时钟背景。{:4_187:}
这个的显示时间好像不对呢{:4_173:}

小文 发表于 2024-11-2 10:30

厉害,好漂亮的钟!喜欢{:4_189:}

小辣椒 发表于 2024-11-2 13:24

自己制作时钟,{:4_199:}

小辣椒 发表于 2024-11-2 13:24

时间代码是不是有错误,现在的时间不准了
页: [1]
查看完整版本: 沙发挂钟可做背景图片