Move content to the bottom of a div element while the user is scrolling

I have a website that functions smoothly with typical user scrolling. Nevertheless, I am interested in incorporating a feature where the user is automatically moved to either the bottom or center of the div element upon scrolling. The elements in question likely have a height of 100vh. Could someone provide assistance with this? Appreciate it!

Answer №1

add this snippet to your index.js file

and include custom code or var elm

        var element = ".et_pb_section";
        $(element).each(function (index) {
            // handle mouse wheel event individually
            $(this).on("mousewheel DOMMouseScroll", function (e) {
                e.preventDefault();
                var delta = 0;
                if (!event) event = window.event;
                if (event.wheelDelta) {
                    delta = event.wheelDelta / 120;
                    if (window.opera) delta = -delta;
                } else if (event.detail)
                    delta = -event.detail / 3;
                var moveTop = $(window).scrollTop();
                var elementSelecter = $(element).eq(index);
                // scrolling from top to bottom
                if (delta < 0) {

                    if ($(elementSelecter).next() != undefined) {
                        try {
                            moveTop = $(elementSelecter).next().offset().top;
                        } catch (e) {}
                    }
                    // scrolling from bottom to top
                } else {
                    if ($(elementSelecter).prev() != undefined) {
                        try {
                            moveTop = $(elementSelecter).prev().offset().top;
                        } catch (e) {}
                    }
                }
                // animate scroll (0.5sec)
                $("html,body").stop().animate({
                    scrollTop: moveTop + 'px'
                }, {
                    duration: 500,
                    complete: function () {}
                });
            });
        });

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

Unable to display image on React page using relative file path from JSON data

Greetings, this is my initial post so please forgive me if I have missed any important information. I'm currently in the process of creating a webpage using react. My goal is to display content on the page by iterating over a relatively straightforwa ...

What is the process of transferring data from an HTML form to Firebase Realtime Database in Django using Pyrebase?

Currently, I'm facing an issue with transferring data from a form to the Firebase realtime database. Here's my view function. I made some changes by adding a user token, but unfortunately, it hasn't resolved the problem yet. The information ...

GWT 2.5.1 - How to Restrict the Amount of Items Displayed in a Dropdown Menu (ValueListBox)

Currently, I am utilizing a ValueListBox to showcase a range of values for users to choose from. The main issue I am encountering pertains to IE11 and its subpar behavior when interacting with the control: The dropdown list appears all over the place (in ...

Utilize JavaScript on the browser to cache videos, potentially exceeding 10 minutes in length, directly

Currently, I am experimenting with WebRTC and looking to share a video stream with multiple peers. To optimize this process, I believe it would be beneficial to cache certain parts of the video. After exploring Cache Web APIs, I found them to be less effe ...

How to sync two carousels in Bootstrap 5 to slide simultaneously with just one click on the next and previous buttons

I am trying to implement dual sliding carousels using Bootstrap 5, but I am encountering issues with getting them to slide simultaneously. Despite incorporating data-bs-target=".carousel", the synchronization isn't working as intended in my ...

What is the proper way to select the <ul> element within an FTL template?

Can someone provide guidance on how to target a <ul> container within a freemarker template using JavaScript? My goal is to display the content of this specific <ul> element in my FreeMarker template on the web page. Any suggestions on how I ...

Generating one-time passwords in Node.js using Speakeasy with a specified expiration period

I'm currently utilizing https://www.npmjs.com/package/speakeasy for generating OTPs, and I want the expiration time to be set at 10 minutes. Below is the code I'm using for OTP generation: const generateOtp = function generateOtp() { let to ...

Retrieve information from a cell containing HTML formatting

Is there a way for me to save a specific text from a cell in Google Sheets into a variable, and then use it to send an email with the text formatted within an HTML table? For example: Cell in Google Sheets: "Lorem ipsum dolor sit amet. Ut tenetur a ...

Fix for fixed scrolling in the navigation bar

Having a website that receives traffic from different countries, including Portugal and other non-English speaking places, I decided to add a translation option. However, I encountered an issue with Google's translate feature which displays a banner a ...

`Vanilla JavaScript AJAX request without using any external libraries or

Seeking advice on creating an ajax request function that is compatible across various browsers without relying on a javascript framework such as jQuery. Any ideas or suggestions are appreciated! ...

Echarts: scatter plots linked with a line to the axis (resembling the PACF diagram)

I am currently working with echarts (js). Is there a method to link the dot of the scatter plot with the 0 value on the y-axis? I want it to resemble a pacf plot, similar to this example: The desired outcome should look something like this: https://i.sta ...

Place the button focus beside the field to enable activation by either pressing Enter or a mouse click utilizing jQuery

I am looking to find a way to submit the information in the inputbox by either pressing the Enter key or clicking the mouse. Currently, when manually changing focus using the tab key or clicking with the mouse, the information is submitted. This is achiev ...

Comparing v-show(true/false) and replaceWith: Exploring the best practice between Vue and jQuery

Currently, I am in the process of learning vue.js and have a question regarding the best approach to implement the following scenario: https://i.sstatic.net/2YBEF.png https://i.sstatic.net/YCEHG.png The main query is whether it is acceptable in HTML to w ...

ajax receives an empty responseText after sending intermediate data to Python on the backend

Initially, the frontend passed an identification to the backend. The backend utilized this identification to retrieve data from the database. The extracted data then underwent additional processing on the backend before being sent back to the frontend. Be ...

Managing a multitude of instances in Three.js

While working on a scene in three.js that includes a high quantity of instances (around 2000) with 200-300 vertices each, I integrated some postprocessing effects using the EffectComposer. However, I noticed that the performance has been slowing down. Is ...

Leveraging gulp-data to incorporate JSON data into Nunjucks templating

I am looking to incorporate JSON data into nunjucks "set". Here's a simple example: index.html {% set divname='foo' %} {% include 'template.nunjucks' %} template.nunjucks <div class="{{divname}}"></div> Everything ...

What is the most effective way to declare a variable in TypeScript when assigning it within a class?

Is there a more efficient way to define the class variable accountHandler without using any? main.ts private accountHandler: any= {}; private requestLOB: string[] = []; constructor() { if (process.env.ENABLEBackendSwitch === "true&q ...

"Keep the ajax requests flowing, don't forget about the previous

Utilizing the Bootstrap framework version 3.3.7, I am faced with the following code: $('#field_submit').click(function() { //omitted irrelevant parts if (counter == 0) { //no errors encountered, form can be submitted ...

Tracking progress with a dynamic bar from the beginning to the end

Struggling to develop a progress bar that corresponds to project start dates and end dates. With a roster of 100 projects, spanning from mid-2017 to future launches, the aim is to depict progress between 2018, 2019, and 2020. If a project commenced in 2017 ...

JavaScript getting overshadowed by other JavaScript libraries

My current CMS, Liferay, heavily relies on jQuery for various functions. Recently, I introduced a new feature to our website using fancybox. However, I realized that this new addition was causing issues with other jQuery functionalities on the page. Remov ...