簡體   English   中英

JQuery滾動腳本正在頁面底部創建可用空間

[英]JQuery Scroll Script is creating free Space at the bottom of my page

為什么我的腳本在頁面底部創建了可用空間,如何停止它? 我從教程中獲得了代碼,因為這是我自己親自編寫主頁的第一次嘗試。

作者告訴我,只需將代碼粘貼到Body標簽中即可。

       <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
                    $(".contactLink").click(function(){
                        if ($("#contactForm").is(":hidden")){
                            $("#contactForm").slideDown("slow");
                        }
                        else{
                            $("#contactForm").slideUp("slow");
                        }
                    });
                });
                function closeForm(){
                    $("#messageSent").show("slow");
                    setTimeout('$("#messageSent").hide();$("#contactForm").slideUp("slow")', 2000);
               }

    $(document).ready(function() {
      function filterPath(string) {
        return string
          .replace(/^\//,'')
          .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
          .replace(/\/$/,'');
      }
      $('a[href*=#]').each(function() {
        if ( filterPath(location.pathname) == filterPath(this.pathname)
        && location.hostname == this.hostname
        && this.hash.replace(/#/,'') ) {
          var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
          var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
           if ($target) {
             var targetOffset = $target.offset().top;
             $(this).click(function() {
               $('html, body').animate({scrollTop: targetOffset}, 1000);
               var d = document.createElement("div");
            d.style.height = "101%";
            d.style.overflow = "hidden";
            document.body.appendChild(d);
            window.scrollTo(0,scrollToM);
            setTimeout(function() {
            d.parentNode.removeChild(d);
                }, 10);
               return false;
             });
          }
        }
      });
    });
    /*! Smooth Scroll - v1.4.5 - 2012-07-22
    * Copyright (c) 2012 Karl Swedberg; Licensed MIT, GPL */
    </script>

抱歉,這不是您的問題的答案,我應該在留言中發布此消息,但我無權這樣做,

請提供一些JSFiddle鏈接或任何其他在線工具鏈接,我們可以在其中測試您的腳本。

對您的問題的一種猜測是,您在某個地方增加的高度大於瀏覽器的高度,例如,嘗試更改以下內容:

            d.style.height = "101%";

            d.style.height = "50%";

以及超出屏幕高度限制的任何其他div

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM