宁静 发表于 2023-2-19 14:50

看看谁能抓住我

本帖最后由 宁静 于 2023-2-22 13:29 编辑 <br /><br /><style>
#papa { left: -170px; width: 1200px; height: 750px; top:150px; background: rgba(0,0,0,.6) url('https://pan.365.tf/uploads/lxx/20230222/bj.jpg') no-repeat center/cover; box-shadow: 3px 3px 24px #000; position: relative; }
#papa p { margin: 0; padding: 0; }
#papa input { border: none; outline: none; opacity: .75; cursor: pointer; }
#playbox { position: absolute; left: 20px; bottom: 20px; padding: 10px; font: normal 1em sans-serif; color: #eee; background: rgba(255,255,255,.2); border-radius: 8px; backdrop-filter: blur(1px); overflow: hidden; box-shadow: 1px 1px 2px rgba(0,0,0,.15); z-index: 100; }
#btnplay { width: 30px; height: 30px; border-radius: 50%; }
#btnplay:hover { background: #aaa; color: #ff0000; }
#mypic {
        position: absolute;
        left: calc(50% - 110px);
        top: calc(50% - 110px);
        width: 220px;
        height: 220px;
        transition: all .3s;
}
</style>

<div id="papa">
        <img id="mypic" alt="" src="https://pan.365.tf/uploads/lxx/20230222/xz.gif" />
                <div id="playbox">
                <p id="geci" style="font-size: 1.2em; text-shadow: 1px 1px 1px #222">loading ... </p>
                <p style="display: flex; align-items: center; gap: 4px; margin-top: 10px;">
                        <input id="btnplay" type="button" value=">" />
                        <input id="slider" type="range" min="0" max="100" value="0" />
                        <span id="per">00:00</span>
                </p>
        </div>
</div>
<audio id="aud" src="https://pan.365.tf/uploads/lxx/20230222/hhh.mp3" autoplay="autoplay" loop="loop"></audio>

<script>
let moveX = moveY = 160;
let num = (min, max) => Math.floor(Math.random() * (max-min+1)) + min;
let lrcAr = [ ['0.00','李振宁 - 你坏坏'], ['180.00','感谢支持'] ];

mypic.onmousemove = function() {
        let x = this.offsetLeft,
                y = this.offsetTop,
                w = this.offsetWidth,
                h = this.offsetHeight,
                pw = papa.offsetWidth,
                ph = papa.offsetHeight;
        if(x + w + moveX > pw || x + moveX < 0 ) moveX = -moveX ;
        if(y + h + moveY > ph || y + moveY < 0 ) moveY = -moveY ;
        this.style.left = x + moveX + 'px';
        this.style.top = y + moveY + 'px';
}

slider.onmousedown = () => aud.pause();
slider.onchange = () => { aud.currentTime = slider.value * aud.duration / 100; aud.play(); }
btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('playing', () => btnplay.value = '||');
aud.addEventListener('pause', () => btnplay.value = '>');

aud.addEventListener('timeupdate', () => {
        let prog = 100 * aud.currentTime / aud.duration;
        slider.value = prog;
        per.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
        for(j=0; j<lrcAr.length; j++){
                if(aud.currentTime >= lrcAr) geci.innerHTML = lrcAr;
        }
});

let toMin = (val) => {
        if(!val) return '00:00';
        val = Math.floor(val);
        let min = parseInt(val / 60);
        let sec = parseFloat(val % 60);
        if(min < 10) min = '0' + min;
        if(sec < 10) sec = '0' + sec;
        return min + ':' + sec;
}
</script>
<br><br><br><br><br><br><br><br><br><br>

宁静 发表于 2023-2-19 14:51

趣味制作~~开心玩玩

宁静 发表于 2023-2-19 14:51

测试一下,今天抓住小猪吗

宁静 发表于 2023-2-19 14:52

测试一下 可以抓住小猪吗{:9007:}

宁静 发表于 2023-2-19 14:56

鼠标跟踪追着小猪试试

沉默 发表于 2023-2-19 15:00

冲进来看看我会不会抓住

宁静 发表于 2023-2-19 15:01

沉默 发表于 2023-2-19 15:00
冲进来看看我会不会抓住

慢慢试{:9001:}

沉默 发表于 2023-2-19 15:02

宁静 发表于 2023-2-19 15:01
慢慢试

抓不住的{:9009:}

沉默 发表于 2023-2-19 15:05

好像你设置了机关

沉默 发表于 2023-2-19 15:05

再试2次抓不抓得到
页: [1] 2 3 4
查看完整版本: 看看谁能抓住我