收缩页面js+css动画,缩小弹框页面移动至头像处

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>动画示例</title>
  <style>
    /* style.css */
    .popup {
      width: 100vw;
      height: 100vh;
      background-color: lightblue;
      /* 为了演示移动效果,确保弹框是绝对定位 */
      position: absolute;
      left: 50%;
      top: 70px;
      transform: translate(-50%, 0%);
      z-index: 0;
      /* 添加过渡效果 */
      /* transition: all 0.5s cubic-bezier(0.52, 0.22, 0.01, 0.98); */
      transition: all 0.7s cubic-bezier(1, 0.7, 0.5, 1);
    }
    .min {
      width: 50px;
      height: 50px;
      font-size: 1px;
      /* transform: scale(0.7); */
      z-index: 2;
    }
    .min #moveButton {
      width: 10px;
      height: 2px;
      font-size: 1px;
      
    }
    .logo {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 50px;
      height: 50px;
      background-color: rgb(0, 106, 253);
      z-index: 1;
    }
    .flexBox {
      padding-bottom: 60px;
      display: flex;
      flex-direction: column;
      position: relative;
    }
  </style>
</head>
<body>
<div class="flexBox">
  <div class="logo">头像</div>
  <div>
    <div id="popup" class="popup">
      <button id="moveButton">点击移动并缩小弹框</button>
        <span>弹框内容</span>
    </div>
  </div>
</div>
<script>
  document.getElementById('moveButton').addEventListener('click', function() {
    var logo = document.querySelector('.logo');
    var logoBox = logo.getBoundingClientRect()
    var popup = document.getElementById('popup');
    // 缩小弹框大小
    popup.className = 'popup min';
    // 移动到页面的右下角,这里假设页面高度为100vh,宽度为100vw,具体数值可能需要根据实际情况调整
    popup.style.left = `${logoBox.x + 17}px`;
    popup.style.top = `${logoBox.y - 8}px`;
  });
</script>
</body>
</html>
  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值