Buat bilah navigasi tempel yang dapat disembunyikan saat digulir ke bawah dan ditampilkan saat digulir ke atas

mrfdn.com – Mungkin Anda pernah terpikir untuk membuat navbar responsif yang dapat bersembunyi saat di-scroll ke bawah lalu menampilkan navbar saat Anda menggulir layar tanpa harus menggulir ke atas layar.

Ini dapat diatasi dengan menjalankan beberapa baris DOM JavaScript.

Misalnya saya meletakkan navbar di header seperti ini.

<header>
  <nav class="container">
    <a href=" .Site.BaseURL " title=" .Site.Title ">
      <img src=" absURL " class="logo" alt=" .Site.Title " width="60" height="60" />
      <span class="hidden">  .Site.Title <span>
    </a>

    <ul>
       with .Site.Menus.main 
       range .
      <li>
        <a href=" .URL "> .Name </a>
      </li>
       end 
       end 
      <li>
        <!-- search -->
        <a href="/search" aria-label="search button">
          <svg xmlns=" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
            <path
              d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
          </svg>
        </a>
      </li>
    </ul>
  </nav>
</header>

Kemudian atur CSS untuk memperbaiki header.

header 
  position: fixed;
  top:0;
  background: #fff;
  transition: all .5s;
  z-index: 1;

Kemudian saya mengatur javascript untuk menangkap elemen header dan kemudian menjalankan fungsinya.

let prevScrollpos = window.pageYOffset;
window.onscroll = function() 
  let currentScrollPos = window.pageYOffset;
  if (prevScrollpos > currentScrollPos) 
    document.querySelector('header').style.cssText = "top: 0; margin-bottom: 3em; padding: 3em 0; z-index: 1"; 
   else 
    document.querySelector('header').style.cssText = "top: -30em;"; 
  
  prevScrollpos = currentScrollPos;

Setelah menjalankan ini, sekarang saya bisa menyembunyikan fitur navbar saat menggulir ke bawah dan kemudian muncul saat menggulir sedikit ke atas.

Semoga bermanfaat. Itu bersembunyi saat Anda menggulir ke bawah dan muncul saat Anda menggulir sedikit ke atas.

Semoga bermanfaat.

PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch

Tinggalkan Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *