|
发表于 2024-11-22 17:54:17
|
显示全部楼层
IP:亚太地区
老乡我给你做好了。你把这个代码粘贴到你的帖子里。
- <style>
- #oBlk {
- margin-left: 50% ; left: -708px;
- margin-top:100px;
- width: 1416px;
- height: 500px;
- box-shadow: 3px 3px 10px #000;
- overflow: hidden;
- position: absolute;
- }
- #oBlk::before,
- #oBlk::after {
- position: absolute;
- content: '';
- left: var(--curX0);
- top: 0px;
- width: 100%;
- height: 100%;
- background: url('https://pic.imgdb.cn/item/67403a8ad29ded1a8cc54a32.webp') no-repeat center / cover;
- }
- #oBlk::after {
- left: var(--curX1);
- transform: scaleX(-1);
- }
- </style>
- <div id="oBlk"></div>
- <div style="height:420px;"></div>
- <script>
- {
- let blkWidth = oBlk.offsetWidth;
- let step = 1.0, tune = 0,
- curX0 = 0,
- curX1 = blkWidth,
- raf;
- let moving = () => {
- /*
- //自左向右
- curX0 += step;
- curX1 += step;
- if(curX0 >= blkWidth) curX0 = -blkWidth;
- if(curX1 >= blkWidth) curX1 = -blkWidth;
- */
- //自右向左
- curX0 -= step;
- curX1 -= step;
- if(curX0 <= -blkWidth) curX0 = blkWidth;
- if(curX1 <= -blkWidth) curX1 = blkWidth;
- tune = curX1 + (curX0 >= 0 ? 1 : -1);
- oBlk.style.setProperty('--curX0', curX0 + 'px');
- oBlk.style.setProperty('--curX1', tune + 'px');
- raf = requestAnimationFrame(moving);
- };
- moving();
- }
- </script>
复制代码
|
|