通过按下CSS中的按钮来向下滚动

时间:2018-11-16 11:37:00

标签: javascript html css

我有这个html代码:

<div class="get-start-area">
    <input type="email" class="form-control email" placeholder="name@company.com">
    <input type="submit" class="submit" value="Get Started">
</div>

和此js代码:

(function() {
  'use strict';
  var btnScrollDown = document.querySelector('.submit');
  function scrollDown() {
    var windowCoords = document.documentElement.clientHeight;
    (function scroll() {
      if (window.pageYOffset < windowCoords) {
        window.scrollBy(0, 10);
        setTimeout(scroll, 10);
      }
      if (window.pageYOffset > windowCoords) {
        window.scrollTo(0, windowCoords);
      }
    })();
  }
  btnScrollDown.addEventListener('click', scrollDown);
})();

Get Started后,我需要查看联系区域,但是滚动仅需一秒钟,并且我只能看到最近的信息块。那么,如何更改脚本中的值以增加页面滚动时间?

这是联系信息部分的html:

<section class="footer-contact-area section_padding_100 clearfix" id="contact">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <!-- Heading Text  -->
                    <div class="section-heading">
                        <h2>Subscribe!</h2>
                        <div class="line-shape"></div>
                    </div>
                    <div class="footer-text">
                        <p>We`ll send you weekly news to make your app more convinient. Stay tune.</p>
                    </div>

                </div>
                <div class="col-md-6">
                    <!-- Form Start-->
                    <div class="contact_from">
                        <form action="#" method="post">
                            <!-- Message Input Area Start -->
                            <div class="contact_input_area">
                                <div class="row">
                                    <!-- Single Input Area Start -->
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="name" id="name" placeholder="Your Name" required>
                                        </div>
                                    </div>
                                    <!-- Single Input Area Start -->
                                    <div class="col-md-12">
                                        <div class="form-group">
                                            <input type="email" class="form-control" name="email" id="email" placeholder="Your E-mail" required>
                                        </div>
                                    </div>
                                    <!-- Single Input Area Start -->
<!--
                                    <div class="col-12">
                                        <div class="form-group">
                                            <textarea name="message" class="form-control" id="message" cols="30" rows="4" placeholder="Your Message *" required></textarea>
                                        </div>
                                    </div>
-->
                                    <!-- Single Input Area Start -->
                                    <div class="col-12">
                                        <button type="submit" class="btn submit-btn">Send Now</button>
                                    </div>
                                </div>
                            </div>
                            <!-- Message Input Area End -->
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>

所以我不明白为什么脚本无法正常工作。

1 个答案:

答案 0 :(得分:1)

更改这行JS:

window.scrollBy(0, 10);

对此:

window.scrollBy(0, 1);

编辑:
或任何低于10的数字