在调整视口大小之前,不会显示来自 Sharethis.com 的共享按钮

问题描述 投票:0回答:1

我添加了来自 Sharethis.com 的共享按钮。当我刷新页面按钮时,不会出现,但当我调整 wievport 大小时,它会出现。 `

<!DOCTYPE html>
<html lang="en">
<head>
  <script type="text/javascript" src="https://platform-api.sharethis.com/js/sharethis.js#property=63a323358fb8b6001abbbf6b&product=inline-share-buttons&source=platform" async="async"></script>

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
  <title>Article preview component</title>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Kumbh+Sans:wght@500&display=swap" rel="stylesheet">
  <script src="https://kit.fontawesome.com/7ab7d5ca64.js" crossorigin="anonymous"></script>
  <style>
    body {
      font-family: 'Kumbh Sans', sans-serif;
      background: hsl(240, 5%, 91%);
    }
    .arrow {
      width: 70px;
    }
    .pop {
      width: 15rem;
      right: 16rem;
      top: 14rem;
    }
    .arrow {
      width: 5rem;
      color: black;
    }
    #share {
      color: white;
    }
  </style> 
</head>
<body>
  <div id="fb-root"></div>
  <div class="container mt-5">
    <div class="card shadow-lg">
      <div class="row">
        <img src="./images/drawers.jpg" alt="drawer image" class="col-4">
        <div class="col-6 p-4">
          <h1>Shift the overall look and feel by adding these wonderful touches to furniture in your home</h1>
          <p>Ever been in a room and felt like something was missing? Perhaps it felt slightly bare and uninviting. I’ve got some simple tips to help you make any room feel complete.</p>
          <div class="row">
            <img src="./images/avatar-michelle.jpg" alt="michele image" class="col-2 rounded-circle">
            <div class="col-6 mt-3">Michelle Apleton <br> 28 Jun 2020</div>
            <div class="bg-light rounded-circle col-1 p-3 m-3 d-flex justify-content-center" id="button">
              <img src="./images/icon-share.svg" alt="" class="">
            </div>
            <div class="pop position-absolute end-10 d-none" id="popup">
              <div class="row bg-dark rounded text-white py-1 d-flex justify-content-center align-items-center">
                <div class=" col-4 p-2">SHARE</div>
                <div class="col-8 zet sharethis-inline-share-buttons"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script>
    let changeClass = document.getElementById("button").addEventListener('click', () => {
      document.getElementById("popup").classList.remove("d-none")
      document.getElementById("popup").classList.add("d-block")
    })
  </script>
  
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>

`

我把他们的头部代码放到了头部。我尝试了 Z-index,但直到调整视口大小才出现,缩小或扩大并不重要,在这两种情况下都会出现。

html button share bootstrap-5
1个回答
0
投票

我发现了共享按钮默认显示 1 个共享按钮但在视口(窗口)调整大小后显示所有按钮的问题。

这对我来说是一个问题,因为我使用模式弹出窗口来包含共享按钮。

所以我必须将其添加到触发按钮的js文件中:

setTimeout(function () {
    window.__sharethis__.initialize();
}, 150);

需要 150 毫秒的延迟才能给模态时间完成加载。

我的特定项目的完整代码如下所示:

openShareButtonFromContentPage: function (videoId, isVideo) {
$("#hiddenFieldContentPreviewId").val(videoId);
appUi.openModal('modalShare', isVideo ? "Share Video" : "Share Article");       
/*console.log("Delay Share This Initializing");   */
$("#hiddenButtonOpenInfo").click();
setTimeout(function () {
    window.__sharethis__.initialize();
}, 150);

},

© www.soinside.com 2019 - 2024. All rights reserved.