Scrolling into view causes the page to move slightly to the left

After installing a .scrollIntoView element and specifying the location for the content to scroll to, I encountered an issue. When testing it on the website and clicking the button that triggers the scrollIntoView function, the function worked perfectly - scrolling to the desired location and displaying all the relevant content. However, the entire page shifted slightly to the left.

It wasn't very noticeable on desktop, but on mobile or tablet devices, approximately 10% of the content on the left was cut off from the screen. Any suggestions on how to prevent this leftward shift?


.

  <div class="scrolltohere"></div>

<script>
function myFunction() {
  var elmnt = document.getElementsByClassName("scrolltohere");
  elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "start"}); 
}
</script>

Answer №1

After some investigation, I managed to find the solution to the issue at hand. It appears that setting the inline property to "start" was causing the page to shift left. By simply removing this or changing it to "nearest", the problem was resolved.

Make the following adjustment:

elmnt[0].scrollIntoView({behavior: "smooth", block: "start", inline: "nearest"}); 

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

Encountering an issue with Bootstrap and Sass when trying to convert SCSS files to CSS due to an error involving an undefined variable @each $color, $value in $theme-colors

I have a goal to reduce the size of the bootstrap file bootstrap.min.css. After some research, I discovered that utilizing SASS and then SCSS is an effective method to achieve this by importing only the specific components needed. Despite my previous exper ...

Access an attribute using slashes in Jquery

I've been struggling to use jQuery to select an object based on a unique filename attribute. However, I'm facing issues with escaping slashes when the selector is created using a variable. Despite spending hours trying different combinations, I s ...

I'm having issues with my navigation bar, and the border on the right side is not functioning correctly

I've been struggling to get the right border positioned between each section of my nav bar. I've tried wrapping each word in a separate span, but it doesn't seem to cooperate. The borders end up on the side and are too small to fill the enti ...

Triple the Charts: Highcharts Vue Component combines three dynamic charts into one powerful visual tool

looking for help with creating a complex chart Hello, I have a task of creating what seems to be 3 charts in one design. I am able to create the two scattered charts, but the column charts are proving to be challenging. Thanks to Wojciech Chmiel, I manage ...

How can Watir retrieve the inner html content of a <span> element?

Currently, I am attempting to locate a navigation link by iterating through several spans with the 'menu-item-text' class. My objective is to compare the content within the span tags to determine if it matches the correct navigation control for c ...

Tips on using Jquery to animate an element to a specific pixel measurement

My expertise lies in executing the following code: $("#nurseView").animate({"left": "+=100px"}, "slow"); However, I am facing a dilemma. How can I animate an object to exactly 1576px on the X-axis regardless of its current position? The code snippet abov ...

What are some ways I can adjust the spacing between the four quadrants on my webpage using HTML/CSS?

After successfully creating four equi-sized/quadrants on my page using the solution found here, I now want to give them some breathing room. The current layout looks like this: https://i.sstatic.net/8acjm.png I attempted adding margin and padding to the ...

The child element is bigger than its parent due to the maximum height set. There is no visible overflow

My goal is to create a parent element with a maximum height, and have a child element fill this parent. If the content in the child exceeds the parent's dimensions, a scrollbar should appear. I attempted to achieve this by: div.parent { max-hei ...

Is there a way to identify the top five elements that are most frequently occurring in the array?

I've successfully found the element that appears the most in an array, but now I'm facing a new challenge where I need to identify the top 5 elements that appear most frequently. Here is the array: [ "fuji", "acros", &q ...

Timeago.js employs language-specific configurations

I am currently utilizing timeago.js to showcase the data stored in the DB as '...hours ago'. The issue I am facing is that I need to translate this into pt_BR. I looked at the documentation and tried implementing it in my ReactJS code, but unfort ...

Adding items to an array in Angular using the subscribe method

In my Angular application, I have an empty array defined as follows: users: any = []; Within the ngOnInit lifecycle hook, I make a service call to fetch data and store it in the users array like so: ngOnInit() { //Fetching data from a JSON endp ...

The border color for the tr element is not showing up as expected in Internet Explorer 7

Encountering a problem that seems to be specific to IE-7. Everything is working fine on FF, Chrome, and IE 8/9 but for some reason IE 7 is not displaying the border color on tr elements properly. Any suggestions for a CSS, jQuery, or Javascript workaroun ...

updating information automatically on page every X seconds for Angular component

I am trying to implement a way to automatically refresh the data of an Angular component every 30 seconds. Currently, I have used a simple setInterval function like this: this.interval = setInterval(() => { this.refresh(); // api call ...

Symbol positioned beside the text in a react-select multiple label

Currently utilizing the react-select library, I am attempting to display icons next to the text of each label that can be added or removed using multiSelect. const data = [ { label: <svg /> && 'keyword one', value: 'keyword o ...

Refreshing the three.js scene seamlessly within a single-page web application

I am currently working on a single page application that consists of multiple "slides," each implemented as a different hidden div, which becomes visible when it is the current slide. One of these slides features a canvas element and a ThreeJS scene. The ...

Using jQuery to update text for corresponding element upon input change

I'm working on a user-friendly ICE card generator. Users can input their information in the form fields and see a live preview below. While the current code functions correctly, it requires repetitive copying and pasting for each input/element pair. ...

Exploring the Dynamic Routing Features of Next.js

After diving into Next.js, I found the learning curve to be manageable since React was already familiar territory for me. Currently, my focus is on implementing dynamic routing in my application - Starting with my live/index.js file - (Where I utilize ge ...

Issue with Tailwind CSS classes not refreshing after initial React app compilation

Today, I took the leap and upgraded from tailwind v2 to v3 for my react app. The upgrade process went smoothly, but now I'm facing an issue where additional tailwind CSS classes added in development are not being picked up after recompilation followin ...

Choose dropdown menus that are pre-filled by JSON may require a manual refresh to show the content

Occasionally, I encounter an issue with a JSON file used to populate select boxes, where the items in the drop down fail to display until the page is refreshed. Despite no errors in the console or log, the loading is seamless on most occasions, leaving me ...

React Native can trigger a press event, as long as it is not within

My situation involves triggering an action when clicking on the parent component (TouchableOpacity, for example), but not triggering anything when clicking on the children components (Screen and others). It's similar to preventing bubbling on the web. ...