Implement a sliding effect to the horizontal scrolling mechanism

Recently, I developed a straightforward horizontal scroll system. You can check out an example of my work on JSFIDDLE: http://jsfiddle.net/marcus_derem/qn603h8b/133/

The Goal:
I am aiming to scroll to a container's child using the following code:

document.getElementById(target_subpage_id).scrollIntoView(false);  

Unfortunately, adding animation options is not possible as the Safari browser does not support it. Check out more details here.

My Query:
Is there a way to incorporate slide animations into the system on JSFIDDLE? Or would I need to rework the mechanics entirely?

~Thanks in advance Markus.

Answer №1

If you want to achieve smooth scrolling, consider using CSS:

html {
  scroll-behavior: smooth;
}

However, it's worth noting that browser support for this feature may not be optimal.

There are alternative methods available as well. You can explore more options by visiting the following page: https://css-tricks.com/snippets/jquery/smooth-scrolling/

// Scroll to specific values
// Similar to scrollTo
window.scroll({
  top: 2500, 
  left: 0, 
  behavior: 'smooth'
});

// Scroll a certain distance from the current position 
window.scrollBy({ 
  top: 100, // negative values allowed
  left: 0, 
  behavior: 'smooth' 
});

// Scroll to a specific element
document.querySelector('.hello').scrollIntoView({ 
  behavior: 'smooth' 
});

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

Using JQuery and Bootstrap: Adding an image from a selection of images to a carousel

As a beginner in the world of JQuery, I am currently working on creating a customizable carousel where users can select pictures to add to the carousel with just one click. On the left side of the page, there is a selection of images to choose from, while ...

Tips for maintaining color on <a> tags even after they have been clicked

My webpage has 3 <a> tag links to 3 different pages. I have set the hover state color to red, and now I want the background-color of the clicked page to remain as it was in the hover state. How can I achieve this? <html lang="en"> < ...

Inquiring about CSS classes for numerous elements

table.rightlist td { text-align:right; } table.rightlist th { text-align:right; } This code snippet is intended to align both the table cells (td) and headers (th) to the right within a table with the "rightlist" class. However, upon testing the ...

Challenges with displaying css/bootstrap classes within angular2

Experiencing difficulties with CSS/Bootstrap integration when displayed in an angular2 component. When attempting to display the CSS and HTML content in the Index.html file (with proper CSS and JS references), everything functions correctly. However, once ...

Error: No @Directive annotation was found on the ChartComponent for Highcharts in Angular 2

I'm having trouble integrating Highcharts for Angular 2 into my project. After adding the CHART_DIRECTIVES to the directives array in @Component, I encountered the following error in my browser console: EXCEPTION: Error: Uncaught (in promise): No ...

Encountering the issue "Error: Uncaught PDOException - SQLSTATE[42000] - Syntax error or access violation: 1064"

I encountered an error that says: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064. It seems to be a syntax error in my SQL statement. Can you help me figure out what's wrong with it? require_once "dbconnect.inc.php"; $e ...

Optimizing Shader Caching in WebGL: Best Practices

I am currently in the process of developing a WebGL application, and I have encountered some challenges with shader storage... In most examples, shaders are directly written in plaintext within the xHTML file itself. However, this approach can lead to clu ...

Receiving an `Invalid module name in augmentation` error is a common issue when using the DefaultTheme in Material

After following the guidelines outlined in the migration documentation (v4 to v5), I have implemented the changes in my theme: import { createTheme, Theme } from '@mui/material/styles' import { grey } from '@mui/material/colors' declar ...

transfer the form file to php using ajax requests

I am trying to send a file to PHP using AJAX. Below is the code I have written, but when I run it, I get an error saying "Undefined index: thefile". Can anyone help me identify the problem? HTML function sendData(url){ var xmlHttp = new XMLHttpRequ ...

Creating a Custom FlatList Content Container with React Native

Is it possible to customize FlatList items with a custom component? I want to create a setup where my FlatList items are encapsulated within a custom component similar to the following: <ScrollView pt={8} px={16} pb={128} > <Card e ...

Maintaining the state of a React component across page refreshes, with a preference for storing the

As a newcomer to React, I am utilizing localstorage in my React app to store certain data that is needed for page refreshes along with the useEffect() hook. My only concern is that I wish to find a way to conceal this particular data, as it seems I cannot ...

What does the "done" callback function entail in Node.js?

Many npm packages commonly utilize a "done" callback function in their code. I find it challenging to grasp its purpose. For instance: passport.serializeUser(function(user, done) { done(null, user.id); }); From what I can gather: The "done" function a ...

Ensuring the authenticity of a Node.js model through the utilization of

Recently, I've been working on developing a NodeJS application using JavaScript and MySQL. As the object I'm handling started to grow in complexity making it difficult to read, I received a recommendation to implement the builder pattern. In resp ...

Maintain consistency of elements inside a div even when its size is adjusted

I'm working on some code that's supposed to create a notebook opening effect, but I'm running into an issue. <html> <style> #container { position:absolute; width:570px; height:360px; } inn ...

Creating an arrow icon alongside a pseudo:hover::before element

This is my custom code snippet: .privacycheck1 { position: relative; top: 265px; background-color: #CF0000; width: 24px; height: 24px; left: 843px; border-radius: 50px; border: 5px #E60000; } .privacycheck1::before { position: relative ...

Conduct a text search within mongoDB to retrieve the corresponding reference document for every item stored in the collection

I am in the process of developing a search functionality for a collection of trips. This search feature will check if the trip includes specific city names (origin and destination). Each trip entry contains the user ID of the person who created it. The sea ...

How can I change the background color of the initial word in a textbox?

In my HTML, I have a text box input. While I am familiar with how to use CSS to set the background color of the entire textbox using background-color, I am wondering if it is possible to specifically target and change the background color of only the first ...

Error encountered: Unable to access attributes of an object that is not defined (specifically trying to read 'clientX')

Hey there! I'm having some trouble moving figures while moving the cursor. It's strange because I've done the same thing on another page and it worked perfectly: const scaleFactor = 1 / 20; function moveItems(event) { const shapes = do ...

Updating the value of an input field seamlessly without the need to reload the page

I am currently working on implementing AJAX to provide auto-complete suggestions for users as they type. At the moment, I have successfully configured AJAX to display the necessary results for the auto-complete functionality in the 'suggestions' ...

The function given to requestAnimationFrame is not being triggered as expected

I have successfully implemented an infinite loop animation using setInterval. However, I want to enhance the performance by switching to requestAnimationFrame(). Unfortunately, the function supplied to requestAnimationFrame() is not being called for some r ...