我的弹出窗口在页面顶部打开

时间:2020-12-30 18:59:05

标签: javascript html css web

enter image description hereenter image description here我使用 html css 和 javascript 创建了一个网页。在主页中,我添加了一个弹出式联系按钮和表单,它正在工作,但在页面顶部打开了弹出窗口。主页就像您滚动的一页。我将按钮添加到页脚,但表单在页眉附近打开。我希望它在用户看到页面末尾时打开。我希望我能解决问题。

https://github.com/ipeksaygut/website 在此链接中只有主页的 HTML-CSS-JS 文件。

我真的是初学者,我真的不明白这个问题。感谢帮助!

-如果有什么需要让我知道以解决问题! 窗口被视为图片,但我想在页面末尾看到它

1 个答案:

答案 0 :(得分:0)

嗨 Ipek Saygut!

我把这段代码放在一起,让你了解你的 css 发生了什么。我修改了 .popUp 类以解决这个问题。请注意,您需要阅读有关 HTML 和 CSS 最佳实践的更多信息。请阅读这篇文章,让您在 HTML 和 CSS 的奇妙世界中入门,别担心,这需要练习,但您很快就会掌握它。 HTML & CSS Best Practices.

我当然希望这段代码有帮助,玩得开心,伙计!

let btn = document.querySelector("button");
let cont = document.querySelector(".popUp");

btn.addEventListener('click', function(){
  cont.id = "show";
});

cont.addEventListener('click', function(e){
  if(e.target == this){
  this.id = "hidden";}
  e.preventDefault;
});
body {
    font-family: 'Red Hat Display', sans-serif;
}

.footer {
    border-top: 5px solid #00acc8;
    height: 200px;
    background-color: #000;
    padding: 50px;
    margin: auto;
}

.container {
    justify-items: left;
    align-items: bottom;
    z-index: 2;
    padding-top: 55px;
    padding-left: 18px;
}

button {
    width: 140px;
    height: 60px;
    font-size: 16px;
    font-weight: bold;
    color: #2e9ca5;
    border: 2px solid #2e9ca5;
    border-radius: 5px;
    background: white;
    transition: all 0.5s ease;
    cursor: pointer;
}

button:hover {
    background: #2e9ca5;
    color: white;
}

#show {
    visibility: visible;
    animation: pop 0.5s ease-in;
}

@keyframes pop {
    from {
        opacity: 0;
        visibility: hidden;
    }
    to {
        opacity: 1;
        visibility: visible;
    }
}

#hidden {
    animation: out 0.5s ease-out;
}

@keyframes out {
    from {
        opacity: 1;
        visibility: visible;
    }
    to {
        opacity: 0;
        visibility: hidden;
    }
}

.popUp::before {
    content: "x";
    font-size: 30px;
    color: #8FC1C1;
    position: fixed;
    right: -35px;
    top: 4px;
}

.popUp {
    display: block;
  margin-top: 5% !important;
    background: rgba(0, 0, 0, 0);
    width: 50%;
    height: 100%;
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 99999;
    transform: translate(-50%, -50%);
    justify-items: center;
    align-items: center;
    visibility: hidden;
}

form {
    display: flex;
    flex-direction: column;
    width:85%; 
  margin:0 auto;
    grid-template-columns: 150px;
    grid-template-rows: repeat(10, 30px);
    grid-row-gap: 10px;
    background: white;
    padding: 30px;
    border-radius: 5px;
    border: 1px solid #2e9ca5;
}

input,
textarea {
    border-radius: 3px;
    border: 1px solid #f2f2f2;
    padding: 0 6px;
}

input[type=text],
input[type=email] {
    height: 30px;
}

input[type=textarea] {}

input[type=submit] {
    height: 30px;
    background: #2e9ca5;
    color: white;
    font-weight: bold;
    transition: background 0.3s ease;
    border: 0;
    border-radius: 5px;
}

input[type=submit]:hover {
    background: white;
    color: #2e9ca5;
}

.remove {
    justify-content: end;
    align-items: end;
}

label {
    color: #b3b3b3;
}
<!DOCTYPE html>
<html>
   <head>
      <title>Discover To Istanbul</title>
      <link rel="stylesheet" type="text/css" href="css/main.css">
      <link href='https://fonts.googleapis.com/css?family=Roboto&display=swap'>
      <link href="https://fonts.googleapis.com/css?family=Parisienne&display=swap" rel="stylesheet">
      <link href="https://fonts.googleapis.com/css?family=Roboto:100,400&display=swap" rel="stylesheet">
      <link href="https://fonts.googleapis.com/css2?family=Red+Hat+Display&display=swap" rel="stylesheet">
      <link href="https://fonts.googleapis.com/css2?family=Red+Hat+Display:wght@400;900;600&display=swap" rel="stylesheet">
   </head>
   <body>
      <div class="menu-bar">
         <div class="menu-banner">istanbul</div>
         <div class="menu-button">
            <ul>
               <li><a href="index.html">HOME</a></li>
               <li><a href="#anc2">DESTINATIONS</a></li>
               <li><a href="#anc3">GALLERY</a></li>
            </ul>
         </div>
      </div>
      <script src="js/main.js" type="text/javascript" defer></script>
      <div class="main-header">
         <center>
            <div class="header-tab">
               <h1>İSTANBUL</h1>
               <div class="header-alt">Let's Go On The Adventure with us !</div>
               <div class="header-alt2"> EXPLORE ISTANBUL </div>
            </div>
            <div class="header-tab-video">
               <header>
                  <video autoplay=""  style="filter:contrast(1.099) brightness(0.92)" preload="none"  muted="" loop="" width="780" height="560">
                     <source src="image/video.mp4" type="video/mp4">
                  </video>
                  <div id="overlay">
                     <p>Istanbul is  <span class="typed-text" ></span></p>
                  </div>
               </header>
            </div>
         </center>
      </div>
      <a name="anc2">
         <div name="#anc2" class="places" id="sacred">
      </a>
      <h1>sacred places</h1>
      <h5>explore most impressive sacred places with us.</h5>
      <a href="html/sacredplaces/sacredplaces.html"><h6> discover more</h6> </a>
      </div>
      <div class="places" id="palaces">
         <h1 id="flt-rght"> palaces</h1>
         <h5 id="flt-rght">explore most attractive palaces with us.</h5>
         <a href="html/palaces/palaces.html">
            <h6>discover more</h6>
         </a>
      </div>
      <div class= "places" id="oldbuildings">
         <h1>old buildings</h1>
         <h5>Explore breathtaking and beautiful buildings with us.</h5>
         <a href="html/oldbuildings/oldbuildings.html">
            <h6>discover more</h6>
         </a>
      </div>
      <div class="galeri">
         <h1><a name="anc3" style="text-decoration:none;">#discoverTurkey</a></h1>
         <h2>VIDEO <font color=red>|</font> PHOTO </h2>
         <div class="galeri-alt">
            <div class="galeri-ic" id="galeri1"></div>
            <div class="galeri-ic" id="galeri2"><a href="https://www.youtube.com/watch?v=LLLbIW71auQ" target="blank"><img src="image/play-button1.png"></a></div>
            <div class="galeri-ic" id="galeri3"></div>
            <div class="galeri-ic" id="galeri4"></div>
            <div class="galeri-ic" id="galeri5"><a href="https://www.youtube.com/watch?v=laKuSeKmaic" target="blank"><img src="image/play-button1.png"></a></div>
            <div class="galeri-ic" id="galeri6"></div>
         </div>
      </div>
      <div class="kayangörseller"
      <center><p style="font-size:60px""font-family:Calluna;">Social Media</p></center>
      <div class="images">
         <marquee  direction="right" scrollamount="7">
            <a href="https://www.instagram.com/p/CI3iV5yr416/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/galata.jpg" style="width:400px;height:400px;"> </a>
            <a href="https://www.instagram.com/p/CI3huz5LGDw/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/c.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3h9xCLXPy/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/ayasofya.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3iMZXLZy9/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/fenerrum.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3iaZlLn-N/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/kapalicarsi.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3iikbrmdw/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/sultanahmet.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3isMKLXrS/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/taksimanit.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3i9RALySO/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/yerebatan.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3xiRiryIn/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/a.jpg" style="width:400px;height:400px;">
            <a href="https://www.instagram.com/p/CI3i1EWrZQr/?utm_source=ig_web_copy_link" target="_blank">
            <img src="image/t.jpg" style="width:400px;height:400px;">
         </marquee>
      </div>
      </div>
      <div class="map">
         <center>
            <iframe src="https://www.google.com/maps/d/u/0/embed?mid=1D66DY_D1-yifqdWfN4_k4mrj_S_JukO6" width="640" height="480" ></iframe>
         </center>
      </div>
      <footer>
         <div class="footer">
            <div class="social">
               <img src="image/instagram.png"><img src="image/youtube.png"><img src="image/twitter.png"><img src="image/facebook.png">
               <div class="container">
                  <button>Contact Us</button>
               </div>
               <div class="popUp">
                  <form>
                     <label for="fn">First Name</label>
                     <input type="text" name="fn">
                     <label for="ln">Last Name</label>
                     <input type="text" name="ln">
                     <label for="email">Email</label>
                     <input type="email" name="email">
                     <label for="notes">Comments</label>
                     <textarea name="notes" rows="5" cols="5"></textarea>
                     <input id='submit' type="submit" value="Submit">
                     <p style="color:#b3b3b3;"> Pop-Up Facts, Recommendations,Interesting Routes... More For Istanbul! </p>
                  </form>
               </div>
            </div>
            <div class="social" style="width:300px;">
               <p>This website prepared for web design course by Kadir Has University students.</p>
               <p>Ayça Çiçekdağ</p>
               <p>Emre Karağaç</p>
               <p>Hilal Pelin Akyüz</p>
               <p>İpek Saygut</p>
               <p>Sude Arslan</p>
            </div>
            <div class="social" style="width:180px;" id="logoalt"></div>
         </div>
      </footer>
      <div class="kayanyazi">
         <marquee direction=right bgColor="#2e9ca5" text-color="white">FIND ISTANBUL-EXPLORE ISTANBUL WITH US  !  | by Ayça Çiçekdağ , Emre Karağaç,Hilal Pelin Akyüz
            İpek Saygut,Sude Arslan
         </marquee>
      </div>
   </body>
</html>

相关问题