简体   繁体   English

当用户向下滚动时,如何使第一个视图中的向下箭头消失?

[英]When a user scroll down, how I can make the down arrow in the first view disappear?

I want to make the down arrow icons disappear when a user scroll down the page.当用户向下滚动页面时,我想让向下箭头图标消失。 Although I searched it on another question of stackoverflow, I cannot find a solution.虽然我在stackoverflow的另一个问题上搜索了它,但我找不到解决方案。 I made jQuery code.我制作了 jQuery 代码。 I am not sure it is correct or not.我不确定它是否正确。

在此处输入图片说明

this is the code on fiddle https://jsfiddle.net/92mtjzew/这是小提琴上的代码https://jsfiddle.net/92mtjzew/

main.js主文件

$(document).ready(() => {
    $('#slideshow .slick').slick({
        autoplay: true,
        autoplaySpeed: 2000,
        dots: true,
    });
});

$(document).ready(() => {
    $('#userReview .slick').slick({
        autoplayhttps://jsfiddle.net/92mtjzew/#: true,
        autoplaySpeed: 8000,
        dots: true,
    });
});

$(window).scroll(function(){
    if($(".box").toggle($(this).scrollTop() === 0) || ($(this).scrollTop() > 0)) {
       $('.box').show();
   } else {
       $('.box').hide();
   }
});

index.html索引.html

 <!DOCTYPE html>
 <html lang="en">
 <head>
    <meta charset="UTF-8">
    <title>Tutorial</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
 </head>
 <body>
   <div id="header">
    <div class="logo">
    <h1><img src="img/logo.png" widht="473px" height="50px"></h1>
    </div>
    <div class="nav">
        <label for="toggle">&#9776;</label>
        <input type="checkbox" id="toggle" />
        <div class="menu">
            <a href="http://joeynamiki.com/" target="_blank">Work</a>
            <a href="about.php">About Us</a>
            <a href="#">Services</a>
            <a href="https://medium.com/@wcgwd1" target="_blank">Blog</a>
            <a href="contact.php"><span>Contact Us</span></a>
        </div>
    </div>
    </div><!-- /#header -->

    <section id="slideshow">
        <div class="slick">
            <div><img src="img/image1.jpg" width="1274px" height="640px" alt=""></div>
            <div><img src="img/image2.jpg" width="1274px" height="640px" alt=""></div>
            <div><img src="img/image3.jpg" width="1274px" height="640px" alt=""></div>
        </div>
    </section>

    <div class="box">
        <span onclick="scrollDown()"></span>
        <span onclick="scrollDown()"></span>
        <span onclick="scrollDown()"></span>
    </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.min.js"></script>
<script src="js/main.js"></script>
<script>
function scrollDown(){
    var businessPage = document.getElementById("businessPage");
    businessPage.scrollIntoView();
}
</script>
</body>
</html>

style.css样式文件

@media only screen and (max-width: 2000px) {
html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    background: linear-gradient(#FBDA61, #FF3CAC);
    overflow-x: hidden;
    color: cornsilk;
}
a {
    text-decoration: none;
}        
h1 {
    font-size: 26pt;
}
button {
    text-transform: uppercase;
    font-weight: bold;
}
html {
    font-family: "helvetica neue", sans-serif;
}

.box {
    position: absolute;
    top: 94%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1;
    display: fixed
}
.box span {
    display: fixed;
    width: 20px;
    height: 20px;
    border-bottom: 3px solid white;
    border-right: 3px solid white;
    transform: rotate(45deg);
    margin: -10px;
    transition: all .3s;
    position: absolute;
    top: 50%;
    left: 50%;
    overflow: hidden;
    z-index: 1;
    animation: animate 2s infinite;
}

.box span:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: white;
  z-index: -2;
}
.box span:before {
  content: '';
  color: cornsilk;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0%;
  height: 100%;
  background-color: #d3d3d3;
  transition: all .3s;
  z-index: -1;
}
.box span:hover {
  color: #fff;
}
.box span:hover:before {
  width: 100%;
}
.box span:nth-child(1) {
    opacity: 0.3;
    z-index: 1;
}
.box span:nth-child(2) {
    opacity: 0.5;
    z-index: 1;
}
.logo h1 {
    margin: 0px
}
.logo img{
    text-align: left;
    float: left;
    padding: 15px 0 0 0;
}
.nav {
    border-bottom: 1px solid #EAEAEB;
    text-align: right;
    height: 80px;
    line-height: 70px;
    background-color: black;
}

.menu {
    margin: 0 30px 0 0;
}
.menu a {
    clear: right;
    text-decoration: none;
    color: cornsilk;
    margin: 0 10px;
    line-height: 70px;
}

span {
    color: #54D17A;
}

label {
    margin: 0 40px 0 0;
    font-size: 26px;
    display: none;
    float: right;
    color: cornsilk;
}
#toggle {
    display: none;
}
#slideshow {
    position: relative;
    top: 0px;
    left: 0px;
}
#slideshow {
    div {
            width: 100%;
            height: 300px;
    img {
            width: 100%;
            height: auto;
        }
    }
}

Try the following example试试下面的例子

.hidden{display:none !important;}

$(document).ready(function(){       
    var scroll_pos = 0;
    $(document).scroll(function() { 
        scroll_pos = $(this).scrollTop();
        if(scroll_pos > 210) {
            $('.box').removeClass("hidden");
        } else {
            $('.box').addClass("hidden");
        }
   });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM