NavigateToTop/BackToTheBeginning

I'm facing a challenge with a page layout that involves two vertical div's - one for the menu on the left and another for loading content on the right. My goal is to utilize the .scrollintoview() function on the menu div so that when a link is clicked, it remains aligned at the top.

Additionally, I would like to implement scrolling functionality specifically within the left div. After exploring a solution in this fiddle, I attempted to apply it to each link in my code but encountered issues with it not functioning correctly.

A snippet of my code:

//script for scrollintoview
$(".fleft #01").click(function() {
  var target = document.getElementById(".fleft #02");
  target.parentNode.scrollTop = target.offsetTop - target.parentNode.offsetTop; 
});

//script for loading content on the right div
$(document).ready(function () {
  $('.fleft #01').click(function () {
    $('.fright').load('div1.html .innerRight');
  });
  $('.fleft #02').click(function () {
    $('.fright').load('teste2.html');
    var data = $(this).html();
  });
  $('.fleft #03').click(function () {
    $('.fright').load('teste3.html');
  });
})

Here's an example of my code in action.

Answer №1

Take a look at this demo http://jsfiddle.net/LJ4S7/.

 $("li a[data-page]").on("tap", function(){
    var targetPos = $(this).closest("li").position();
    var height = $(".fleft").get(0).scrollTop;       
   $(".fleft").animate({
      scrollTop: parseInt(height,10) + parseInt(targetPos.top,10)
    }, 1000);
});

There was an 's' character causing issues in your fiddler.

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

Rearranging jquery tags through dragging and reorganizing according to ID and mouse movement

Can anyone recommend a component similar to the one demonstrated in "Categorizing tags" on this page? I am facing some challenges: I need the ability to rearrange tags using the mouse (drag and drop). I have a predefined set of tags and I want a list of ...

"Troubleshooting the issue of jQuery addition not functioning correctly within an AJAX

Is there a way to add the result value to an already existing value in a specific textbox? I've noticed that concatenation is working, but addition is not. $.post('includes/ajax_timesheet.php', { 'action': 'add_kitamount&ap ...

Enhancing CSS to create a more visually appealing loading spinner

I am completely new to CSS and I've been attempting to customize the CSS in the angular-loading-bar module to create a more visually appealing loading spinner. Currently, I have a square spinner that rotates in the center of the page, with a black bor ...

Alert: Mouse Exiting Window - Moodle Prompt

I have created an online exam using the Moodle platform, coded in PHP. I am now looking for a way to prevent test-takers from navigating away from the test by implementing a mouseover pop-up. Below is the code I have for triggering an alert pop-up when th ...

React function causing website to freeze upon dispatch

I created a function in the child component to handle checkbox selection and trigger setDispatch(true). Unfortunately, whenever I check the checkbox, the website freezes and stops responding until I close and reopen it. Here is the function: const [ ...

Passing the unique identifier of a record in NextJS to a function that triggers a modal display

I'm currently facing an issue with my NextJS component that displays a list of people. I have implemented a delete button which triggers a modal to confirm the deletion of a person, but I am struggling with passing the id of the person to be deleted. ...

Discovering repeated values and verifying the value range within table columns can be achieved through the use

Within my table, I have two columns labeled Min Range and Max Range. My objective is to identify duplicate values within these columns while ensuring that no row definition overlaps another. The image below illustrates this concept: https://i.sstatic.net/ ...

Utilizing a variable beyond the confines of the script tag

Is there a way to assign the value of my variable place to my variable address, even though they are not in the same script tag? I want to bind the value and utilize it for fetching data. When I log my variable place, I can see the address, but I am unsure ...

Converting Excel VBA code to Javascript for use in Google Sheets: A step-by-step guide

Hello everyone, I am looking to convert a VBA code that I wrote into javascript and integrate it into Google Sheets. Does anyone have any suggestions on how I can accomplish this task? The VBA code in question is as follows: Sub Influencers_automacao() ...

How can I deliver assets in React without the PUBLIC_URL showing up in the path?

I have set up a portfolio website that includes my resume. I am trying to make it so that when someone visits the route http://localhost:3000/resume.pdf, they can view my resume directly. The resume.pdf file is located in my public folder. However, instead ...

Optimizing Wordpress by Efficiently Enqueueing Javascript

As a beginner with a WordPress website, I am aware that in order to execute scripts on a WordPress page, they need to be enqueued in the functions.php file. However, I'm unsure about the correct process for this. The specific JavaScript file I want t ...

Property that is dynamically populated based on data retrieved from an external API

My template relies on an API call (Firebase) to determine the return value of my computed property, which in turn decides whether certain elements are displayed. However, I've noticed that my computed property is not reactive - its value in the templ ...

Guidelines on centering an AJAX spinning animation within a parent div

Below is the basic structure of an HTML document for a webpage. <div class="grand-parent"> <div class="header">Heading</div> <div class="parent-div"> <div class="child-div-1"></div> ...

Upon initial login, React fails to retrieve notes

I developed a note-taking React app using the MERN stack with React Router DOM v6. When I initially visit the website, I am directed to the login page as intended. However, upon logging in, the page refreshes but does not redirect to the home page. This is ...

Establishing session management for tasks in Node.js

I'm currently developing a web application using Node JS and encountering an issue with the session store in req. For my sessions to work, I have set up my app.js like this: // Enable sessions app.use(session({ secret: '***********', ...

Notify when a certain element's ID is visible on the screen using the jQuery appear method

Having trouble getting this plugin to cooperate: https://github.com/morr/jquery.appear I attempted to reference the plugin from a CDN using Ajax: http://cdnjs.cloudflare.com/ajax/libs/jquery.appear/0.3.3/jquery.appear.js Why isn't it working as expe ...

Tips for replacing spaces with &nbsp; in a string using ReactJS and displaying it in HTML

<div className="mt-2 font-sidebar capitalize"> {item.title} </div> item.title can vary and be any string retrieved from the backend, such as "all products", "most liked", "featured items", etc. I am looking for a solution to subst ...

Sluggish Bootstrap Carousel Requires Mouseover or Click to Start Sliding

Having Trouble with Bootstrap Carousel Sliding: I've been trying to solve this issue for a while now, but nothing seems to be working. I know this might be a common question, but I really need to fix this problem quickly and none of the suggested solu ...

Navigate between paper cards with Polymer's side scrolling feature

I recently started using Polymer after a long break from HTML and have been relying on stack-overflow and Google's polymer guide for guidance. Currently, I am working on a product catalogue project and I have already started coding the paper-cards for ...

What are the consequences of submitting a form to a different website through POST method?

Dealing with a CMS that does not offer an easy way to add a NodeJS route for handling form data can be quite challenging. I'm considering the following setup - would this be considered bad practice or unsafe? Server 1 (Ghost CMS) : www.domain.com &l ...