"Explore stunning images with the power of JavaScript in our

My question involves a div containing five images, displayed in order as [1] [2] [3] [4] [5]. I am looking to create a JavaScript script that will automatically rearrange the images to display them as [2] [3] [4] [5] [1], then [3] [4] [5] [1] [2], and so on. So far, I have only been able to make the first image change. Is it possible for all the images to change using the current script I have? Thank you in advance. (Note: I do not know jQuery, I am a beginner in JavaScript.)

var i = 1;
var x = ["img/facebook.png", "img/linkedin.png", "img/mail.png", "img/twiter.png", "img/skype.png"];
var y = ["1", "2", "3", "4", "5"];

function slide(num) {
    
    i = i + num;
 if(i < 0) i = x.length - 1;
 if (i > x.length - 1) i = 0 
     document.getElementById('image01').src = x[i];
 document.getElementById('text01').innerHTML = i;
}

function autorun(){setInterval("slide(1)", 3000);}
body{margin: 0; padding: 0; color:#fdbf7d; font-family: courier new;}
.container{margin-left:auto; margin-right:auto; width:940px; padding:10px; background-color: yellow;}
#photo_gallery_container{background-color: brown;}
#photo_gallery{}
<!doctype html>
<html lang="en">
<head>
   
   <title>Gallery</title>
   
   <meta http-equiv="content" content="text/html"; charset=UTF-8>  
   <link rel="stylesheet" type="text/css" href="style.css"/>
   
</head>

<body onload="autorun()">
   <div class="container">
      <div id="photo_gallery_container">
     <div id="photo_gallery">
 <center>
    <img id="image01" src="img/facebook.png" width="100px" height="100px">
    <img id="image02" src="img/linkedin.png" width="100px" height="100px">
    <img id="image03" src="img/mail.png" width="100px" height="100px">
    <img id="image04" src="img/twiter.png" width="100px" height="100px">
    <img id="image05" src="img/skype.png" width="100px" height="100px">
<span id="text01">1</span>&nbsp;&nbsp;&nbsp;
<span id="text02">2</span>&nbsp;&nbsp;&nbsp;
<span id="text03">3</span>&nbsp;&nbsp;&nbsp;
<span id="text04">4</span>&nbsp;&nbsp;&nbsp;
<span id="text05">5</span>&nbsp;&nbsp;&nbsp;
 </center>
 </div>
 <script type="text/javascript" src="myscript.js"></script>
  </div>
   </div>
</body>
</html>

Answer №1

To achieve this, you have the option of duplicating the image and placing it following the final image:

var currentImage = $('#image01').clone(); //duplicate image
$('#image01').remove(); //delete original image
var finalImage = $('center img').eq(x.length-1); //obtain last image
currentImage.insertAfter(finalImage); //add duplicated image after last image

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

Building a website using Bootstrap: A step-by-step guide

Wondering how I can incorporate all the cool Bootstrap components into a webpage. Is there a tool that offers live preview? Back in the day (web 1.0), Dreamweaver was my go-to for creating HTML and basic CSS, but what are some current tools where I can si ...

Placing three div elements within a container, one of which has a height set to auto

I need help arranging 3 divs side by side using float:left. The height for two of the div's (child1 and child3) is fixed, but there is no set height for child2 - I would like child2 to have the same height as the container div. <div id="container ...

Tips for preserving the horizontal scroll position of a div following a toggle using the "blind" effect

My intention is to replicate the functionality demonstrated here: http://jsfiddle.net/cbp4N/17/ $('#cbxShowHide').click(function(){ if(this.checked) { $('#block').show('fast',function() { $(this).scrol ...

Issue encountered when attempting to execute a JavaScript AppleScript from another JavaScript AppleScript due to permissions error

I am in the process of organizing my .applescript files by separating them into different ones for better organization. Within my JS AppleScript file named Test.applescript, I am attempting to execute another JS AppleScript file called Group Tracks Depend ...

Exploring the font variables in the asset pipeline of Rails 7

Creating a habit of defining a set of root variables is crucial for maintaining consistency throughout an application. :root { --main-font-family: "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif; --kbd-font-family: Consolas, "Libe ...

Tips for deactivating the highlight on a previously selected menu item when clicking on the next menu option in Angular.js

In my pages, I have a menu where the landing page menu is initially highlighted. However, when I move to the next menu, the previous landing page highlight remains instead of being removed while swapping the menu. I am using Angular.js and angular ui-route ...

Encountering an error when trying to execute JavaScript in Node: Uncaught SyntaxError - An unexpected identifier was found

Although the code below works perfectly fine in a browser, I encountered an error when trying to run it via node (in the command prompt) which reads: Uncaught SyntaxError: Unexpected identifier Please refer to the attached screenshot for details. //inde ...

Is jQuery failing to correctly validate the RadioButtonList?

Using jQuery, I am attempting to validate a RadioButtonList to make sure that the user has selected one of the values. If none of the radio buttons are checked, an alert message should appear. However, even after selecting a radio button, the alert continu ...

Struggling to trigger the click event for a button located within the Item template of RADorgChart

Within the item template of a RadOrgChart (a Telerik Control), there is a button that I am trying to use. <asp:UpdatePanel ID="uplDataHierarchy" runat="server" UpdateMode="Always"> <ContentTemplate> <div id="divOrgChart" runat="ser ...

How can I integrate the native calendar of an Android device in Phonegap?

What is the best way to add an event to an Android device's calendar using phonegap? I need to make sure it works on Android Version 2.3 and above. The available plugins are not functioning correctly, so I am looking for alternative solutions. ...

Is it possible to personalize Carousel-indicators within react-bootstrap?

I'm currently utilizing the Carousel component from . My goal is to customize the carousel-indicators, adding text and making them appear as buttons with text. However, when I attempt to do so, React renders 'ol' tag into a new CarouselItem ...

Interactive Communication: PHP and JQuery Messaging Platform

I am developing a social networking platform and I am looking to integrate a chat feature. Currently, I have a home.php page that displays a list of friends. The friends list is loaded dynamically using jQuery and PHP, like this: function LoadList() { ...

Create a circular shape using CSS that dynamically adjusts its size to match the width

Can you help me with a CSS challenge? I need to create circles around elements on a webpage, but my code is not working perfectly. The width of the circle is off and I can't seem to center it properly. The width does not match the content (it is alw ...

Investigate the CSS display property of an element using JavaScript

Can JavaScript be used to determine if an element's CSS display == block or none? ...

Utilize Lodash to group by ID and calculate the sum in order to assign the new sum value

Is it possible to use Lodash to sort and group by a specific key (such as "id") and update the values of the elements by adding all unique values of another key (e.g. payout)? For example, can we take the array below: [ { id: 1, payout: 15, ...

Dimensional adjustments for Semantic-ui dropdowns

Currently, we are attempting to transform bootstrap into semantic-ui. <select id="sayfaArama" class="ui search dropdown"> <option value="">Searching in pages...</option> </select> Take a look at this image I have encountered ...

Utilizing Angular2 to name dynamically generated sets of radio buttons

As a novice in web development and Angular2, I am facing an issue with an Angular2 component tasked with creating a tree view on a webpage using the angular-tree-component library. In this tree, each node is associated with a popover HTML template containi ...

Unrestricted heading for a spreadsheet

My goal is to create a table with a leftmost header column that has no border, but is still part of the table. In my attempt to achieve this, I used the following HTML code: <table class="my-table" style="border-left: 0"> <tr> < ...

Using the mt-downloader module in a Node application is a straightforward process

Hey there, I'm looking to incorporate the Multi downloader module into my project. I've checked out the GitHub link, but unfortunately, there are no examples provided on how to actually use this module. I came across this example and tried implem ...

Prevent the ability to select multiple options in one multiselect box depending on the choices made in a separate mult

I am working with two multi select boxes, one for a country list and one for a state list <select multiple="multiple" name="country[]" id="country" > <option value="0">Select a Country</option> <?php foreach($country_li ...