I am attempting to create a presentation featuring the identical title

How can I enhance this code by turning it into a slideshow with additional images while maintaining the h1 and h2 tags within it? Here's the existing code displaying an image with titles overlayed on top:

<header class="header-image">
    <div class="headline">
        <div class="title">
            <h1>SanDesigns</h1>
            <h2>The RENDERS you are looking for</h2>
    </div>
  </div>
</header>

CSS:

.header-image {
display:block;
width:100%;
background:url(Matthias_Leuzinger_test_Test_exterior_BB_View01_.jpg)  no-repeat;
min-height:605px;
margin-top:-1px; 
}

.title {
padding-left: 15%;
padding-top:5%;
font-family:GeosansLight;
}

.title h1 {
width: 18.75%;
border:3px solid #FFFFFF;
background-color:#7A7A7A;
text-align:center;
color:#FFF7F7;
}

.title h2 {
border:3px solid #FFFFFF;
background-color:#7A7A7A;
text-align:center;
width:30%;
color:#FFF7F7;
}

I have another code snippet that enables slideshow functionality, although it lacks the ability to incorporate divs with h1 and h2 tags:

<nav class="navbar">
<ul>
    <li><a href="#inicio">Inicio</a></li>
    <li><a href="#diseños">Diseños</a></li>
    <li><a href="#articulos">Articulos</a></li>
    <li><a href="#equipo">Equipo</a></li>
    <li><a href="#contacto">Contacto</a></li>
</ul>
</nav>
<header class="slideshow">
<img class="header-image" src="Architectural-Photorealistic-3D-Renders.jpg">
<img class="header-image" src="Channel-Place-Residence_LA.jpg">
<img class="header-image" src="Matthias_Leuzinger_test_Test_exterior_BB_View01_.jpg">
<img class="header-image" src="p2010018-20110510-view1-modepark.jpg">
</header>

And here's the accompanying script:

<script>
var slideIndex = 0;
carousel();

function carousel() {
var i;
var x = document.getElementsByClassName("header-image");
for (i = 0; i < x.length; i++) {
  x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {slideIndex = 1}
x[slideIndex-1].style.display = "block";
setTimeout(carousel, 6000); // Change image every 6 seconds

}

Answer №1


<script>
var slideIndex = 1;
showDivs(slideIndex);

function plusSlides(n) {
  showDivs(slideIndex += n);
}

function showDivs(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  if (n > slides.length) {slideIndex = 1}
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
     slides[i].style.display = "none";
  }
  slides[slideIndex-1].style.display = "block";
}
</script>

<h2 class="w3-center">Manual Slideshow</h2>

<div class="w3-content" style="max-width:800px;position:relative">

<img class="mySlides" src="img_fjords.jpg" style="width:100%">
<img class="mySlides" src="img_lights.jpg" style="width:100%">
<img class="mySlides" src="img_mountains.jpg" style="width:100%">
<img class="mySlides" src="img_forest.jpg" style="width:100%">

<a class="w3-btn-floating" style="position:absolute;top:45%;left:0" onclick="plusSlides(-1)">❮</a>
<a class="w3-btn-floating" style="position:absolute;top:45%;right:0" onclick="plusSlides(1)">❯</a>

</div>

For more information, please visit this link:http://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_self

Answer №2

To change your background using JavaScript, you will first need to assign an id to your header div:

HTML

<header class="header-image" id="changingHeader">
    <div class="headline">
        <div class="title">
            <h1>SanDesigns</h1>
            <h2>The RENDERS you are looking for</h2>
    </div>
  </div>
</header>

JAVASCRIPT

<script language="javascript">
var currentImg = 1;
function changeBg(imgNumber){

var images = ['img1.jpg','img2.jpg','img3.jpg','img4.jpg','img5.jpg']

document.getElementById('changingHeader').style.backgroundImage = "url("+images[imgNumber]+")";
if (currentImg <= 3){
      currentImg ++;
}else{
currentImg = 0;
}

}
setInterval(function(){
    changeBg(currentImg);
}, 5000);  // this will run every 5 seconds
</script>

CSS

.header-image {
display:block;
width:100%;
background:url(img1.jpg)  no-repeat;
min-height:605px;
margin-top:-1px; 
}

.title {
padding-left: 15%;
padding-top:5%;
font-family:GeosansLight;
}

.title h1 {
width:18.75%;
border:3px solid #FFFFFF;
background-color:#7A7A7A;
text-align:center;
color:#FFF7F7;
}

.title h2 {
border:3px solid #FFFFFF;
background-color:#7A7A7A;
text-align:center;
width:30%;
color:#FFF7F7;
}

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 iterating through a JSON response in an Ember template

Here is the content of my JSON array: { "object": { "assignments": [ { "assignmentId": 14706368, "sectionId": 0, "assignmentTitle": "file attachment A", "assignmentSta ...

Click the button to initiate the download of a file using curl

I'm looking for assistance with modifying a script. Currently, the file is downloaded to my server upon refreshing the page. However, I would like it to start the download only when a button is clicked. Below is the code snippet: //File to save the c ...

What is the best way to keep the calendar of a Datepicker always visible while still being able to select a date easily?

When I write my code, the calendar only appears when I press the TextBox. I attempted to place the datepicker in a <div>, but then I was unable to retrieve the selected date. @model Plotting.Models.CalendarModel @using (Html.BeginForm("Calendar", "H ...

What role does the index number play in MongoDB/Mongoose and why is it important?

When using mongoose with Mongo DB, this is how I set up indexes: UserSchema.index({ email: 1, username: 1 }, {unique: true}); Initially, I only had the email field indexed. However, since usernames must also be unique and I need to check if a username ...

Avoiding redundancy by establishing the loading state in a redux reducer

Let's dive into a concrete example to better illustrate my point. In the webapp I'm working on, users can apply for jobs using a job reducer that handles various actions such as creating_job, created_job, fetching_job, fetched_job, fecthing_jobs, ...

Tips for consuming a REST API to retrieve JSON data and assign it to a variable for use in React JS

I'm currently working on developing a shopping application using React.js. I found inspiration from a sample application on https://codepen.io/paulkim/pen/oZLavq , and now I am looking to fetch product information from an API call. I have attempted to ...

Discover updates within a JQuery Ajax call

I am sorry if this question sounds simple, but I would like to know how to set up a function that triggers when the Ajax data changes from the previous request. window.setInterval(function(){ $.get("feed", function(data){ if (data.changed ...

Intermittent rendering problems in Chrome due to CSS printing with a fixed header and footer

I am attempting to customize the format of an e-commerce receipt for printing, including a fixed header and footer that will appear on every printed page. However, I am encountering intermittent issues. Sometimes, the layout works correctly, while other ti ...

Styling the top rows of a Datatable

I am working with a Datatable that includes the following elements at the top: Dropdown for Items per page Buttons Paginator Currently, each item is displayed on separate rows, but I would like to add some styling and I'm unsure of how to do so. C ...

Having trouble getting the OwlCarousel directive to function properly

I have successfully created elements in the DOM, but for some reason, the plugin is not rendering the template. I am unsure if the problem lies with the plugin itself failing or if the Angular directive is not functioning as it should. Can someone please h ...

Joining strings together using double quotes inside the parentheses of a function

It's recommended to utilize the function in this manner: $function.share("msg");. However, I am interested in appending a variable to the strings. $function.share("https://www.youtube.com/watch?v="+$Id+""); Unfortunately, it seems to be not function ...

Switching between various dropdown options does not produce any noticeable differences in the (React) interface

I am experiencing an issue with my dropdown menu where selecting different values no longer triggers any changes. This was working perfectly fine before. Below is the code I am using: context.js: import React, { useState, useEffect } from 'react&apo ...

Decoding Azure table results in Node.js: A comprehensive guide

I need guidance on how to properly parse a query result in Azure using Easy API. I have encountered difficulties with creating an object inside the function(results) since it causes an endless loop and eventually results in a httpcode 500 error. I'm s ...

How can I use jQuery to prevent a click function from running when input fields are left empty

I have step cards with input fields on each card. A "Next" button is provided for each card to change the view. However, I need to prevent the "Next" button from functioning if any input fields on the form are left empty. Below is the code snippet: va ...

What could be causing the lack of data for the current user?

I have been attempting to fetch the current user session and display the data in the view, but nothing is appearing. I even checked the database and confirmed an active session with all the necessary information. I attempted logging the user out and starti ...

The height auto transition in CSS3 begins by shrinking to a height of 0 before expanding to

My CSS code looks like this: .foo { height:100px; overflow:hidden; -webkit-transition: height 200ms; -moz-transition: height 200ms; -o-transition: height 200ms; transition: height 200ms; } .foo.open { height:auto; } When the ...

How can I add a % symbol to user input in a text input field?

When utilizing a number spinner, I'm looking to include the % symbol in the input box by default. I attempted using a span, however, it places the symbol outside the box. ...

The GitHub-hosted package encounters a failure during the npm publish process

Last week everything was running smoothly, but now I am encountering an error and not sure what went wrong. (Apologies for the formatting as there are many lines of log) Running Node version: v10.15.3 Using npm version: 6.4.1 After executing npm publish ...

Displaying SVGs in the <object> tag within an Angular 2 component is not functioning properly in Internet Explorer

When embedding an SVG within an <object> tag, it is not displayed in IE 11 and Edge. Instead, they only show the innerHTML as "SVG no supported," giving the impression that the tag is not supported at all. Interestingly enough, both browsers do d ...

Combining mouse interactions with animated bar transitions

I want to create a graph with dynamic bar height transitions whenever it is drawn or redrawn. Once the bars are displayed, I would like mouse events (mouseenter, mouseleave, and mousemove) to trigger a tooltip showing information about the specific bar bei ...