Use jQuery to smoothly navigate to a designated pixel position by scrolling down the page

Is it possible to use jQuery to scroll down a page to a specific pixel?

I am currently working on a website with a fixed navigation bar that scrolls to an anchor point when a button is clicked, utilizing the jQuery smooth scroll plugin.

The issue I am facing is that the navigation bar overlaps the section, cutting off half of the text.

Given the rise in popularity of jQuery animated websites, I believe others may have encountered this problem before but I have been unable to find a solution.

I have integrated the Smooth Scroll plugin into the Wordpress site in question and the following code is located within the section:

<div id="web"></div>, <div id="app"></div>, <div id="seo"></div>

There are three sections in total that each button should scroll to.

Website URL: www.gogoblondie.com

Answer №1

Forget about using weird plugins ;)
Here's a simple solution for you:

CHECK OUT THE LIVE DEMO

  <nav>
    <ul>
      <li><a href="#web">WEB</a></li>
      <li><a href="#app">APP</a></li>
      <li><a href="#seo">SEO</a></li>
    </ul>
  </nav>  

  <div id="web" class="page" style="margin-top:200px;">WEB</div>
  <div id="app" class="page">APP</div>
  <div id="seo" class="page">SEO</div>

CSS:

nav{ 
  position:fixed;
  top:0px;
  width:100%;
  height:200px;
  background:#cf5;
  z-index:2;
}
.page{ 
  position:relative;
  min-height: 800px; 
}

jQ:

var navHeight = $('nav').outerHeight();

$('nav a').click(function( e ){
  e.preventDefault();
  var myHref = $(this).attr('href');
  var newPos = $(myHref).offset().top;
  $('html, body').stop().animate({scrollTop: newPos-navHeight}, 1300);
});

Answer №2

jQuery scrollTo is a fantastic plugin that allows smooth scrolling to a specified element while also offering an offset option.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to position my h1 headings above my flexbox containers?

I have set up 3 flexbox containers, with one container controlling the other two. In the primary and secondary containers, I have placed 4 images and an h1 element together. Now, I'm trying to figure out how to move the h1 elements on top of the flex ...

Click on all the links in the array to open them in separate tabs

I currently have an array that looks like this: myArray = ["", ""] The issue I am facing is that when trying to open them all in separate tabs, the code I'm using concatenates all the URLs together and attempts to open them as one. If anyone has a ...

The currency exchange script is malfunctioning and not functioning properly

Is there a solution for accessing the JSON value that is currently eluding me? If anyone has any suggestions, I would greatly appreciate it. function forex() { var to = document.getElementById("to").value; alert(to); var from = document.getE ...

Magnify novice mistakes: Unhandled promise rejection and Ensure every child has a distinct "key" property

Currently, I am working through Amazon's Getting Started with AWS tutorial found here: https://aws.amazon.com/getting-started/hands-on/build-react-app-amplify-graphql/module-four/ After successfully building and hosting the app on git, I noticed that ...

IE displaying "slow script" alert due to Knockout malfunction

Within my grid of observables and computed observables, the first row serves as a multiplier for all subsequent rows. Users can modify this percentage rate and Knockout automatically updates all relevant values accordingly. Additionally, I require a textbo ...

Ways to invoke a child component's function in React Native

I need to invoke a component function from a sibling component and I've opted to do it through the parent component and refs. Here's my parent component SMS-Registration.js import React, {Component} from 'react'; import PhoneNumber fr ...

Ways to ensure a div remains at the bottom of a page without using a wrapper

I am currently working on my website and this is the content I have in my body tag: #social-media { width: 175px; margin-left: auto; margin-right: auto; padding-top: 10%; } #social-media img { padding: 5px; } #soci ...

JSON Serialization of numeric data types

It came to my attention that the website generates the same Base64 string for payloads containing numerical values written in different notations. An interesting example is the output for these two payloads: { "value": 0.000001 } { "val ...

Tips on how to automatically rearrange a jQuery UI sortable list

Currently, I am working with 2 jQuery UI sortable lists which can be found at http://jqueryui.com/demos/sortable/#connect-lists. The process involves dragging items from list A (catalog) to list B (basket). I have a specific requirement where I need the ...

Utilizing jQuery to process date input in a Rails form

I have been utilizing the jquery_datepicker gem to choose dates in my form. However, the datepicker is passing parameters in this format: {"appointment"=>{"starts_at"=>"04/07/2012"}, "commit"=>"Submit", "id"=>"915"} However, Rails mandates th ...

From PHP to JavaScript, the looping journey begins

Question I am attempting to display markers on a map using PHP to fetch the data, then converting it into JavaScript arrays for marker addition. Below is an example of my code: Database query require_once("func/connect.php"); $query = "SELECT * FROM sit ...

Within the mobile view, a button with accompanying description will be discreetly concealed

Working on an ASP.NET Core MVC project, with a FAQ section in the view displayed as follows: <div class="container"> <div class="row "> <div class="col-xl-2 mx-auto d-none d-sm-block"> ...

How to bring RxJS 6 into your browser?

With the widespread support for JavaScript modules in all modern browsers, I am experimenting with importing code directly in the browser using import. Utilizing unpkg.com for npm modules and exploring the jspm project that converts npm modules into a form ...

What is the reason for the failure of this react ternary return statement?

My slideboard is set up to show a warning component (currently just a "test" div) when the prop "columnsItem" exceeds 50. Everything works fine, but when I switch back to a slideboard with fewer columns, all I see is a blank white screen. Can you help me ...

Develop an innovative showcase page showcasing 151 individual profiles with React Router

I am new to using React Router and feeling a bit confused about how to proceed. On my homepage, I have 151 unique monster thumbnails. When a user clicks on a thumbnail, they should be directed to the specific monster's 'show page'. Currently ...

Prepare the column data for Vue Good-Table by formatting it beforehand

I've created a custom Vue.js component that retrieves orders from a Woocommerce store. These orders include product variations and are received in object form. Before displaying the data in a table, I need to format the object accordingly. This is a ...

Tooltip not appearing when user hovers over it

I need help with displaying tooltips only when hovering over anchor tags. Initially, I have hidden the visibility and want to show it on hover. However, the tooltips are not appearing when I hover over them and there are no console errors displayed. Can so ...

Generating URL parameters for Ajax requests on the fly

My current project involves creating a dynamic form where the number of fields displayed changes based on the user's selection from a dropdown menu. This means that depending on what option they choose, anywhere from 2 to 20 different fields may be sh ...

Storing a date in MySQL using Vue.js and Node.js

My current tech stack consists of nodejs and express.js for the backend, vuejs for the frontend, and mysql as the database. I am facing an issue where I cannot send a date retrieved from localStorage to my mysql database. Whenever I try to send the date, ...

Switch between using the useState hook by toggling it with the MUI Switch

Looking to implement a custom Dark Mode feature for a specific element on my create-react-app website using MUI. I have successfully implemented the Switch to change the state on toggle, but I am having trouble figuring out how to toggle it back and fort ...