如何加的空白在引导,直到某些元件是在屏幕上?

0

的问题

我有这种图像在我的网站,在举4和想像是在我的用户的屏幕时的某些按钮或图像是点击的通过加入空白的底部的网站因此图像是在屏幕上当我的网站是滚动的所有方式下(我已经想通了与JS功能)。 怎么可以不断增加空白的网站,直到的图像上屏幕上? 我已经想出了一个解决方案具有某些元素在CSS与利润的固定测量和有时可见的点击,但是希望它可以对各种大小的视.

scrollingElement = (document.scrollingElement || document.body);

function scrollSmoothToBottom (id) {
  $(scrollingElement).animate({
     scrollTop: document.body.scrollHeight
  }, 500);
}
window.onload = function(){
// Make WhiteSpace not on website
document.getElementById("whiteSpace").style.display = "none";
document.getElementById("submitButton").addEventListener("click",function(){
// Once Button is clicked make whitespace visible then scroll to bottom
document.getElementById("whiteSpace").style.display = "block";
scrollSmoothToBottom ();
});

}
.space{
 margin:520px; 
}
         <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <center>
        <h1 id  = "collegeNameTitle">Name</h1>
        <h3>Student Size</h3>
         <span class="badge badge-success even-larger-badge" id = "collegeStudentSizeText">10</span>
         <h3>Acceptance Rate:</h3>
          <span class="badge badge-success even-larger-badge" id = "collegeAcceptanceRateText">10</span>
          <h3>Student-Faculty Ratio:</h3><span class="badge badge-success even-larger-badge" id = "collegeRatioText">10</span>
        </center>
<center><button id = "submitButton"><img class = "collegeImage"src="sample.png" id  = "collegeImage"></button></center>
<div id = "whiteSpace" class ="space" visibility = "hidden">
  </div>

如何我想我的网站。 这是我的代码现在想要它如此,在CSS我没有固定测量的空间,但直到的图像到达顶端。

bootstrap-4 css html javascript
2021-11-24 00:12:03
1

最好的答案

0

如果你只想要的位置你的 img 要是在你的屏幕当你点击一个 button 然后你可以尝试的代码如下:

const theImg = document.getElementById("myImg");
const theBtn = document.getElementById("myBtn");
theBtn.addEventListener("click", function(){
  theImg.style.position="fixed";
  theImg.style.top=0;
});
body{
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-item: center;
  justify-content: center;
}
img{
  height: 5rem;
  width: 100%;
}
<button id="myBtn">Button</button>
<img id="myImg" src="https://www.w3schools.com/css/paris.jpg">

如果你不熟悉职位css然后,它将会是最好的,你要检查 这个文档.

2021-11-24 01:05:47

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................