Interactive Jquery Slideshow for Mobile Devices

Help needed to arrange images in a slideshow format! The images are currently scattered on the webpage and causing confusion. Thank you in advance for any assistance provided. Below are the HTML, JavaScript, and CSS codes that need to be fixed:

HTML

<!DOCTYPE html>
    <html>
        <head>
        <title>Panda</title>

        <meta name="viewport" content="width=device-width, initial-scale=1"/>
        <link rel="stylesheet" href="jquery.mobile-1.4.0.min.css"/>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />

        <link rel="stylesheet" href="gallerytest.css"/>


        <link rel="stylesheet" href="gallerytest.css"/>
        <script src="jquery-2.0.3.min.js"></script>
        <script src="jquery.mobile-1.4.0.min.js"></script>

        <script src="jquery-ui-1.10.4"></script>
        <script src="slide.js"></script>
    </head>
    <body onload="Slider();"> 
        <div data-role="page" id="Home" data-theme="a">
            <div data-role="header" >
                <div data-role="navbar">
                <ul id="header">
                        <li><a href="home.html"><img src="images/home-black.png"/>&nbsp Home</a></li>
                        <li><a href="donate.html">Donate</a></li>
                        <li><a href="about.html"><img src="images/info-black.png"/>&nbsp About</a></li>
                    </ul>
                </div>
            </div>  
        <div role="main" class="ui-content">
                <h1 style="text-align:center">Gallery</h1>
            </div>
        </div>
        <div data-role="content" >  
        <div class="slider">
                <img id="1" src="images/full/001.jpg" border ="0" alt="Image001" />
                <img id="2" src="images/full/002.jpg" border ="0" alt="Image002" />
                <img id="3" src="images/full/003.jpg" border ="0" alt="Image003" />
                <img id="4" src="images/full/004.jpg" border ="0" alt="Image004" />
                <img id="5" src="images/full/005.jpg" border ="0" alt="Image005" /> 
                <img id="6" src="images/full/006.jpg" border ="0" alt="Image006" />
                <img id="7" src="images/full/007.jpg" border ="0" alt="Image007" />
                <img id="8" src="images/full/008.jpg" border ="0" alt="Image008" />
                <img id="9" src="images/full/009.jpg" border ="0" alt="Image009" />
            </div>
        </div>
        <div data-role="footer">
            <div data-role="navbar">
            <ul id="footer">
                    <li><a href="card.html">Send me a Card!</a></li>
                    <li><a href="donate.html">Donate</a></li>
                    <li><a href="contact.html">Contact me</a></li>
                </ul>
            </div>
        </div>
    </body>
</html>          

CSS

.slider{
    width:600px;
    height:600px;
    overflow:hidden;
    margin:0;
    background-image:url('images/ajax-loader.gif');
    background-repeat:no-repeat;
    background-position:center;
    background:red;
}

JS

$(document).on("pageinit", function() {
    $(".slider #1").show("fade", 500);
    $(".slider #1").delay(5500).hide("slide", {direction:"left"},500);
    var sc=$(".slider img").size();
    var count=2;
    setInterval(function(){
        $(".slider#+count).show("slide",{direction:'right'},500};
        $(".slider#+count).delay(5500).hide("slide"{direction:"left"},500);
        if (count==sc) {
            count=1
        } else {
        count=count+1
        }
    }, 6500);
});

Answer №1

Alright, let's address a few issues with this code and make some corrections to get it up and running smoothly.

First off, we have a couple of conflicting functions - the body onload event (<body onload="Slider();">) and the pageinit function (

$(document).on("pageinit", function Slider() {...});
). These are redundant and causing confusion. Remove the body onload event from your code as it is unnecessary for what you are trying to accomplish.

Next, the class name in your jQuery selector should be just "slider" instead of "slider();". You don't need parentheses here since you're not calling a method. Update .slider() to .slider for correct targeting.

Furthermore, there's an issue with your jQuery selectors in a couple of blocks of code:

$(".slider#1" + count).show("fade", 500);
$(".slider#1" + count).delay(5500).hide("slide", {direction:"left"},500);

$(".slider#+count).show("slide",{direction:'right'},500};
$(".slider#+count).delay(5500).hide("slide"{direction:"left"},500);

In these blocks, you should adjust the selectors to target the desired elements correctly. For example, change $(".slider #1") and $(".slider #" + count) accordingly to show/hide the right elements.

Lastly, ensure all images are initially hidden using CSS property display: none; to avoid any flickering when the slideshow starts.

If your jQuery Mobile setup is accurate (note that I couldn't test mobile functionality on Fiddle), you should now have a functioning slideshow! Hopefully, these adjustments helped you resolve the issues and provided insights for future reference. Happy coding!

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 Typescript to pass the setState function as a parameter

Consider the scenario below: // external file export const specificFunction = setState => { setState({ value: "some new string" }) } // component's file import { specificFunction } from "pathToFile" interface TState { ...

Unable to display Three.JS OBJ Model

I am facing an issue with loading a .obj model in Three.js. I created the model in Cinema 4D, exported it with a scale of 1 meter, and tried to load it using OBJLoader in Three.js. However, even though there are no errors, the model is not showing up. Wh ...

What is the best way to manage the browser tab close event specifically in Angular, without it affecting a refresh?

I am trying to delete user cookies when the browser tab is closed. Is this achievable? Can I capture the browser tab close event without affecting refreshing? If I attempt to use beforeunload or unload events, the function gets triggered when the user ref ...

If the body's height is adjusted, the page will automatically scroll to the top

I'm facing an issue where a button on my HTML page triggers a popup box to open (which covers the background). To prevent the background from scrolling, I am using the following CSS: windowHeight = $(window).height(); $("body").css({ "height": wi ...

If I use npm install to update my packages, could that cause any conflicts with the code on the remote server?

As I navigate through the numerous issues, I stumbled upon the command npm ci that is supposed to not change the package-lock.json file. However, when I attempt to run npm ci, it fails: ERR! cipm can only install packages when your package.json and package ...

Can a sophisticated matrix-like design be created using a CSS grid system?

I'm currently working on implementing a unique grid structure in Material-UI using a CSS grid: Browse the desired complex layout here Here's the current CSS grid layout I've created with Material-UI: View the existing layout here This is ...

Testing jQuery's beforeSend method using Jasmine - A comprehensive guide

I have figured out how to test promises in jasmine, as detailed here, but I am struggling to find a method to test the beforeSend function. var xhr = $.ajax({ url: 'http://example.com', type: 'POST', data: '...', ...

Using jQuery to extract the value of an object from an <li> element and updating the class attribute of the <li> element

There is a div element: <div id="ddDistr" class="searchBoxSortDistrict" tabindex="1"> <ul id="ddd"> </ul> </div> I have inserted HTML from json into it: $("#ddd").html(" "), $.each(dis, function( index, value) { $("#dd ...

Returning output from API

Recently, I have delved into the world of website development. Despite my limited experience in web development, I am hoping that my question isn't too basic. I currently have two Ajax functions implemented on my website. One function retrieves a key ...

Utilize Bootstrap and Jquery to create a collapsible NavBar that hides all links, including dropdown togg

I currently have a bootstrap navbar set up like this: <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container"> <div class="navbar-header nav-tabs" style=" ...

What is the best way to refresh or manually trigger the marker cluster icon update in Google Maps API?

Recently, I implemented a custom cluster HTML marker, where I attempted to dynamically change the color of my markers within the cluster. Despite debugging the code and confirming that the color variable was being updated correctly, the marker colors thems ...

Using Symfony2 to make an Ajax request in order to show a message based on a particular condition

As a novice in the realm of JavaScript and Ajax, I am struggling to find a way to display a message based on certain conditions. Let's consider a scenario where a user can adjust the quantity of a product they wish to purchase. While implementing thi ...

Is there a way to keep the node text in place and prevent overlapping in my D3.js tree?

I'm facing an issue with long text strings in my D3 tree. The nodes move according to the tree structure, but how can I handle excessively long node-text? For instance, if the label "T-ALL" had a longer name, it could overlap with the neighboring nod ...

Click here to navigate to the anchor and expand the accordion

Is there a way to open an accordion panel using an external anchor link? I attempted to use an anchor link, but it only loads the page without opening the panel. My goal is to have the page load, scroll to the panel, and then open the accordion when the ...

extract data from a JSON object

I am in possession of the JSON data shown below: [ { "AVG_VALUE" : "2540", "MAX_VALUE" : "2540", "SUM_VALUE" : "2540", "MIN_VALUE" : "2540", "METRICID" : "100248060212", "START" : "1449216120000", "STARTTIME" : "09:02" } , { ...

Set a variable to store the loaded 3D object and receive an undefined value in return

I've been working on a function to load 3D objects using three.js. My goal is for this function to return the 3D object once it's loaded, but no matter what I try, I keep getting "undefined". function load3DObject(url, meshMaterial) { let mes ...

Converting Excel to JSON Schema using JavaScript

My current task involves creating a form in an Excel sheet where the design is based on the provided data types. For example: https://i.sstatic.net/9v4Cw.png To achieve this, I am working on converting the Excel data into a JSON schema that can be inse ...

Ensure that the div expands to accommodate the content

I'm experiencing an issue where the content within a div with a blue border exceeds the boundaries of the div when it expands. How can I make sure that the div extends to contain all the content? Here is a demonstration of the problem: When I expand ...

Custom error message in JSON response for jQuery validation addMethod/remote

I am attempting to implement a method that emulates the remote method in order to send input data to a web service and receive a JSON response containing error details. Here is an example of the JSON response: { "isError": "true", "errorMessage": ...

Tips for creating an input box that only accepts floating point numbers:

I have a custom component - a text box that I am using in two different places. In one location, it accepts integers and in another, floats. For the integer validation (where dataType=2), I have successfully implemented it. However, for the float validat ...