Utilizing jQuery to create a sliding effect for a div instead of using window.scrollX to slide the entire window

I'm currently facing an issue with my setup where I want only the images to move left or right when I click on the previous/next buttons, without affecting the rest of my website such as the header. Although I have tried using window.scrollX in jQuery, I need assistance in allowing only the div '#imageWrapper' to move while keeping everything else stationary. Any help with this jquery query would be greatly appreciated.

If you'd like to see what exactly I am looking for, please check out my jsfiddle.

Can anyone provide guidance?

Here is my fiddle - http://jsfiddle.net/s2TJQ/441/

$(function() {
    var boxLefts = [];
    $('.images').each(function(i, el) {
        boxLefts.push(this.offsetLeft);
    });
    $("input").click(function(e) {
        var dir = false,
            targetLeft = -1;

        var target = e.target.className;
        if (target == 'next') {
            dir = 1;
        } else {
            dir = -1;
        }
        if (dir) {
            e.preventDefault();
            winLeft = window.scrollX;
            $.each(boxLefts, function(i, v) {
                if ((dir == 1 && winLeft < v && targetLeft < 0) || (dir == -1 && winLeft > v)) {
                    targetLeft = v;
                }
            });
            if (targetLeft >= 0) {
                $('html:not(:animated), body:not(:animated)').stop().animate({
                    scrollLeft: targetLeft
                }, 1000);
            }
        }
        return false;
    });
});

Answer №1

Take a look at my demonstration!

http://jsfiddle.net/s2TJQ/443/

I have made changes to the CSS of:

#imageWrapper - margin-top: 105px;

.siteContent -

margin-bottom: 0px;
width: 100%;
position: fixed;
left: 0px;
top: 0px;

UPDATE: BASED ON YOUR FEEDBACK, I HAVE MADE SEVERAL CHANGES TO THE CODE! Check out this demo and let me know if it functions as intended! http://jsfiddle.net/s2TJQ/446/

PLEASE NOTE: The precise stopping point for sliding is still unresolved!

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

Having trouble accessing property '0' of undefined in angular

Below is the code I am currently working on. My goal is to enable editing of the table upon click, but I encountered the error mentioned below. Could someone kindly explain why this is happening and suggest a workaround? <tbody> <tr *ngFor="l ...

Restrict the amount of items fetched when processing JSON information

Here is a snippet of JSON data that I am parsing using JavaScript. "credits":{ "cast":[{ "id":819,"name":"Edward Norton","character":"The Narrator","order":0,"cast_id":4,"profile_path":"/iUiePUAQKN4GY6jorH9m23cbVli.jpg" }, {"id":287,"name": ...

What are the steps to integrate mailjet into my Vue application?

I am looking to utilize mailjet for my contact form. I have installed it using "$ yarn add node-mailjet" and followed the steps provided. However, I am a bit confused about whether I am integrating mailjet correctly. Below is the code I am currently using: ...

Tips for managing asynchronous code that invokes other asynchronous code in AngularJs

My factory utilizes indexedDB and a method called getRecipe that relies on this indexed db to fetch data. The issue arises because indexedDB returns its instance in an asynchronous call, and getRecipe is another method that also returns its value asynchro ...

Using the useQuery() function in a Next.js React app successfully fetches data from the API on the client side, yet the same API call fails to work when implemented in getServerSideProps on

I am attempting to retrieve data from the backend server using React Query within Next JS getServerSideProps. Here is the function used to fetch the data: export const getGoogleAuthUrl = async () => { const res = await fetch(`${process.env.NEXT_PUBLIC ...

Having trouble converting the JQuery result from the REST request into the correct format

Currently, I am working on making a REST request for an array of objects using JQuery. During the execution of the code within the "success" section, everything works perfectly fine - the objects in the array are converted to the correct type. However, I ...

Tips for testing an HTML email in different email platforms before finalizing the send. Utilizing PHP and Javascript for optimum results

After creating a web app that sends HTML emails using PHP, I wanted to implement a feature that allows users to preview how the email will appear in different email clients such as Outlook and Gmail before sending it out. Despite searching for plugins tha ...

Learn the technique for submitting a checkbox value regardless of its disabled status

I'm currently working on a web page that displays order invoices with pricing. Users can select items by checking the checkboxes and clicking submit. I want to restrict users from unchecking the items once they are selected, and the form should only w ...

Leveraging JavaScript to enable automatic identification of buttons on a webpage

My website features specific buttons placed within articles and also in the head/body/footer sections. I have a plan to make it so that when a user clicks on a button, JavaScript code will determine if the button is inside an article or outside of it, then ...

Vue.js is throwing an error message saying, 'Unrecognized custom element: <ShowList>' while rendering in the browser

After setting up a basic boilerplate project using vue cli create, I made some small modifications that initially seemed to work fine. However, at one point, both of my components suddenly stopped working in the browser without any warnings from vue-cli-se ...

Generating .d.ts files for library packages correctly involves following the right steps

In the process of developing a JavaScript NPM library package, I am trying to instruct TypeScript to generate a .d.ts file using the embedded jsdocs within the files. Let's consider three files in this scenario: File index.js, which serves as the mai ...

What is the best way to show inline icons within menu items?

Issue Upon selecting an option from the menu, I encounter a problem where the icon (represented by a question mark inside a speech bubble) appears on a different line than the text ("Question"). Fig. 1. Display of menu after selection with the icon and t ...

Is there a way to retrieve the data components of "calendarEvents" using the "addEventListener" method?

I am currently trying to customize the "v-calendar" element within the vuetify framework in nuxtJS. My goal is to access the data elements of "calendarEvents" through the use of the "addEventListener" method. However, I am facing difficulties in achievin ...

Why is the image auto-swapping script failing to display images frequently?

I have a script that is currently running to rotate between two different logos on my webpage. What I am attempting to achieve is for the page to load and then seamlessly transition from one image to the other without any blank space. Below is the code I ...

Injecting a full browser-screen DIV into the body of the webpage

Recently, I was tasked with developing a script that could be utilized on any website. As a test, I decided to use the Google search results page. My goal is simple - to have a full-screen semi-transparent div displayed on any site for cookie notification ...

Effortlessly Display or Conceal Numerous Table Columns Using jQuery

I have a small table where I want to hide certain details with a basic button... for instance, table { border-collapse: collapse; } th, td { border: 1px solid gray; padding: 5px 10px; } <button>Show/Hide Details</button> <table> ...

Having trouble retrieving the property from the object that was returned

I'm facing a challenge where I'm unable to properly query the JSON response I receive. However, I can successfully print out the entire response using a msgBox() prompt. Here's an excerpt of the JSON response that I managed to see through th ...

Are there any menu plugins in jQuery that fit the criteria I'm searching for?

I am in the process of creating an AJAX application. I have multiple menus that display a list of options provided by the server. Users have the ability to select or deselect any of these values, and their choices are then saved to the server. For example ...

The controller argument for Ajax data object is found to be empty

Currently, I am attempting to make an ajax call to a controller method that accepts an object. The code I have at the moment is as follows: [HttpPost] public ActionResult EditStudent(Student student) { //do something } Here is the Ajax call I am us ...

Obtain the node identifier within the Angular UI Tree component [angular-ui-tree]

Utilizing Angular UI tree to create a relationship between items and categories has been successful in the default setup. However, a new requirement has emerged to incorporate node/section numbering within the tree for managing hierarchy. I attempted to i ...