|
|

楼主 |
发表于 2022-4-29 17:39
|
显示全部楼层
核心代码:
- <style>
- .outer { text-align: center; }
- .mama { margin: auto; display: inline-block; padding: 20px; vertical-align: middle; position: relative; }
- .sPic { outline: none; }
- .picTip { position: absolute; top: 30px; left: 30px; color: white; font: normal 1.5em / 2em sans-serif; text-shadow: 1px 1px 2px gray; mix-blend-mode: difference; }
- </style>
- <div class="outer">
- <div class="mama">
- <img class="sPic" src="https://638183.freep.cn/638183/t22/h8.jpg" alt="" />
- <div class="picTip">第一张</div>
- </div>
- </div>
- <script>
- let mama = document.querySelector(".mama");
- let sPic = document.querySelector(".sPic");
- let picTip = document.querySelector(".picTip");
- let isGo = true;
- let cuImg = 0;
- let picAr = [
- ["https://638183.freep.cn/638183/t22/h8.jpg","第一张"],
- ["https://638183.freep.cn/638183/t22/h7.jpg","第二张"],
- ["https://638183.freep.cn/638183/t22/h6.jpg","第三张"],
- ["https://638183.freep.cn/638183/t22/h5.jpg","第四张"],
- ["https://638183.freep.cn/638183/t22/h4.jpg","第五张"],
- ["https://638183.freep.cn/638183/t22/h3.jpg","第六张"],
- ["https://638183.freep.cn/638183/t22/h2.jpg","第七张"],
- ["https://638183.freep.cn/638183/t22/h1.jpg","第八张"],
- ["https://638183.freep.cn/638183/t22/hometown.jpg","第九张"]
- ];
- mama.onmousemove = function(e) {
- e = e || event;
- let x = e.clientX - this.offsetLeft;
- let y = this.clientWidth;
- this.style.cursor = `url('https://638183.freep.cn/638183/qd/${x > y/2 ? "next.cur" : "pre.cur"}'), auto`;
- isGo = x > y/2? true : false;
- }
- mama.onclick = function(){
- cuImg += isGo ? 1 : -1;
- if (cuImg >= picAr.length) cuImg = 0;
- if (cuImg < 0) cuImg = picAr.length - 1;
- sPic.src = picAr[cuImg][0];
- picTip.innerHTML = picAr[cuImg][1];
- }
- </script>
复制代码
|
|