What is the best way to add a timer to the slider on this page?

I stumbled upon a solution on the internet that fixed my syntax errors - check it out: http://codepen.io/birjolaxew/pen/yJYLyz

Although I got past one hurdle, I'm now facing another challenge. How can I integrate setInterval so that the radio is checked every second and the next image appears? I tried watching some tutorials, but they didn't provide much help. Maybe if someone could take a look at my code and offer specific advice, I'd better grasp the concept!

Code:

    <!-- Images -->
<div class="fb featuredslider_container">
  <div id="images">
    <img src="https://s-media-cache-ak0.pinimg.com/736x/a4/11/3e/a4113ec2da852f2eaa65af72e96decb6.jpg" />
    <img src="http://cdn.arstechnica.net/wp-content/uploads/2015/09/GooglePlus-logos-02-980x980.png" />
    <img src="http://img05.deviantart.net/6b35/i/2013/015/7/9/the_white_dog_sophie_2_by_thecakemassacre-d5rko7g.jpg" />
  </div>
  <!-- Radio Sutff -->
  <div class="featuredradiowrap">
    <input checked class="featuredradio" id="featureditemslider1" name="itemslider" type="radio">
    <label for="featureditemslider1"></label>
    <input class="featuredradio" id="featureditemslider2" name="itemslider" type="radio">
    <label for="featureditemslider2"></label>
    <input class="featuredradio" id="featureditemslider3" name="itemslider" type="radio">
    <label for="featureditemslider3"></label>
  </div>
</div>

Css:

    .featuredslider_container{
  position: relative;
  width: 500px;
  height: 250px;
  margin: 0 auto 32px;
  overflow: initial;  /* Change to overflow:hidden if you want to see the final product */
  box-shadow: 0 0 0 2px #BFB198;
}
#images {
  font-size: 0;
  /*Remove white space */
  width: 1500px;
  height: 100%;
  animation: move-images 8s infinite;
  position: absolute;
  left: 0;
  top: 0;
}

#images img {
  width: 500px;
  height: 100%;
}


/* Radio Sutff */

input[type="radio"] {
  display: none;
}

.featuredradiowrap {
  position: absolute;
  bottom: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
}

.featuredradio + label:before {
  content: "";
  display: inline-block;
  margin-right: 2px;
  border-radius: 30px;
  background: #00a0ff;
  height: 17px;
  width: 17px;
}

input[type="radio"]:checked + label:before {
  background: orange;
}

Javascript

    var featuredRadio = document.getElementsByClassName("featuredradiowrap")[0];
var images = document.getElementById("images");

function leftAnimation() {
  if (document.getElementById("featureditemslider1").checked == true) {
    images.style.transition = "left 2s linear 0s";
    images.style.left = "0";
  } if (document.getElementById("featureditemslider2").checked == true) {
    images.style.transition = "left 2s linear 0s";
    images.style.left = "-500px";
  }
  if (document.getElementById("featureditemslider3").checked == true) {
    images.style.transition = "left 2s linear 0s";
    images.style.left = "-1000px";
  }
}
featuredRadio.addEventListener("click", leftAnimation);

Answer №1

Give this a shot. Make sure you're targeting the wrapper, not just the inputs.

var featuredRadioButtons = document.getElementsByClassName("featuredradio");
var imagesWrapper = document.getElementById("images");

function moveLeft() {
  if (featuredRadioButtons[0].checked == true) {
    imagesWrapper.style.transition = "left 2s linear 0s";
    imagesWrapper.style.left = "0";
  } else if (featuredRadioButtons[1].checked == true) {
    imagesWrapper.style.transition = "left 2s linear 0s";
    imagesWrapper.style.left = "-500px";
  }
  else if (featuredRadioButtons[2].checked == true) {
    imagesWrapper.style.transition = "left 2s linear 0s";
    imagesWrapper.style.left = "-1000px";
  }
}
featuredRadioButtons.addEventListener("click", moveLeft);

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

Enhancing Image Source URLs with Dynamic Content Using HTML and JavaScript

<img src="https://website.example/convention?plastic_id=**{add-id-here}**&muppet_id=**{add-id-here}**"> I am currently facing a challenge in injecting dynamic content from an external database into the {add-id-here} placeholders. While ...

The variable is unable to be accessed within the PHP function query

After passing a variable through ajax to a function within my php file "Cart_code.php", I encountered an issue where the variable was not accessible inside the function. Can you help me figure out why? Javascript $.ajax({ type: "POST", url: "incl ...

How can we ensure an image fills up the entire screen while still being contained within a Bootstrap 4 container?

I have a unique setup on my Wordpress page template. The content from the parent template is displayed first, followed by the content of child templates, including featured images. I want the content to appear in the container class, while the featured ima ...

Add the text into a div element with a dropdown selection

I'm having trouble with the code below. My goal is to move the selected text to my chosen-locations div. Any suggestions? Thank you! <select name='available_locations' class='select-location'> <option value=&a ...

Customize Color of Bootstrap Tooltips

Is there a way to customize the appearance of BootStrap tooltips by changing the color and aligning the text to the left? I've tried various CSS modifications from different posts, but none seem to work. Any idea on how to alter the CSS of the tooltip ...

How can I show the last li item in a ul element that extends beyond its parent container?

Chat App Development In my current project, I am developing a chat application using React. The app consists of a list (ul element) that displays messages through individual items (li elements). However, I have encountered an issue where the ul element st ...

Having difficulty configuring the option during the call back in the jQuery Plugin

I am working on implementing a customizable minHeight feature for my object. By default, the minHeight is set to be equal to the object's height. However, users have the option to change it using the plugin's configuration options during the cal ...

What could be causing such a significant variance in performance for a wrapped JavaScript function?

Here is a code snippet that I have been experimenting with: function Run () { var n = 2*1e7; var inside = 0; while (n--) { if (Math.pow(Math.random(), 2) + Math.pow(Math.random(), 2) < 1) inside++; } return inside; } var s ...

WebGL Tip: With THREE.MeshFaceMaterial, each face can have its own unique orientation

I am currently exploring the world of 3D graphics by creating a building in WebGL using the THREE.js framework. Having no prior experience with tools like DX or OpenGL, I dove right into the project with the following code snippet. var windowTexture = TH ...

Utilizing i18n within the Vuex store: A guide

I am grappling with an issue in my project where I need to perform translations within the Vuex store. Every time I attempt to translate using i18n inside the store, an error occurs. I have attempted to import and utilize i18n inside the store by using th ...

Center navigation bar text with the class `.justify-content-center`:

Can someone explain why, when I add the class justify-content-center to my Navbar in Bootstrap, the text remains in the left position? https://i.sstatic.net/8x0Yc.png I came across an instruction in the Bootstrap documentation stating that after adding t ...

The CSS dropdown menu is malfunctioning on Internet Explorer and Firefox

After searching for a solution and coming up empty-handed, I have decided to ask a question. The drop-down menu on my computer and other devices at home works perfectly in Chrome but not in Firefox and IE. #menu { position: absolute; left: 50%; bottom ...

Placing an object to the right side

I'm currently developing an app using React Native and I need to position something on the right side of the screen. <View style={searchDrop}> <TextInput style={textInput} placeholder="Search Coin ...

Why is URL Hash Navigation not functioning when linking to a different page's slide on the carousel?

Why isn't the #tag link being recognized? Even though the data-hash items are visible in the URL window, the script doesn't seem to pick them up. The standard script used on the carousel page is as follows: $(document).ready(function() { $( ...

Exploring the Fusion of Data in VueJS

Trying to figure out how to merge data from two different sources to display in a single table. One source is created within my Vue instance, while the other is imported from an API. Any suggestions on how to achieve this? HTML: <div class="ui conta ...

Can you guide me on how to establish a cookie within a selenium webdriver javascript script?

I am trying to figure out how to set a cookie using a basic webdriver script: WDS.sampleResult.sampleStart(); //WDS.driver.manage().addCookie(new Cookie("connect.sid", "s%3AeexeZcd_-S23Uh30e3Dmd4X9PskWF08s6m5hDurDa5Jj66SupmmiqvKEjAg6HGigl0o0V%2B9R7m4", ...

Tips for effectively passing "this" to direct the event initiator in react js?

I'm facing an issue where I am attempting to send a buttons object to a function and then access its properties within that function. Here's my button : <RaisedButton label="Primary" id = "1" onTouchTap={()=>this.buttonPress(this)} prima ...

Traversing an array of objects can result in an extraneous comma being displayed in the markup

View screenshot showing unwanted comma in output Hello there, I'm currently working on a gold shop website and dealing with an array of product objects. When mapping through this array to display products on the main page, I've encountered an is ...

Formatting Date and Time in the Gridview of my Asp.net Application

I have been using this format to display the date and time in a grid. The issue I am facing is that I cannot retrieve the exact HH:MM from the database. Even though the database shows 11:11, my grid is displaying 11:03 instead. Here is the value stored in ...

What is the best method for ensuring that a hover dropdown remains active when clicked on?

Trying to create a drop-down menu with overflow options that extend into the next section upon hover. The goal is for users to be able to click on "Join Now" or "Learn More," but currently, the buttons disappear when moving down. HTML Code: <div class ...