Displaying Text and Images on a Sliding Carousel with a Static Background Image

I am currently experimenting with the Materializecss Image Slider. My goal is to have a fixed full-screen background image while the texts and images slide over it.

Initially, I tried setting the background-color of the slider class as transparent, but unfortunately, it did not work as intended.

$(document).ready(function(){
  $('.slider').slider();
});
 section {
   background: url('http://lorempixel.com/580/250/nature/4') center center no-repeat;
  background-size: cover;
}


.slider .slides {
 background-color: rgba(255,255,255,0);
  margin: 0;
  height: 400px;
}
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8>
  <title>Customizing Materialize Slider</title>

      <link rel="stylesheet" href="css/style.css">
      <link rel="stylesheet" href="css/materialize.css">


  
</head>

<body>
  <section>
   <div class="slider">
    <ul class="slides">
      <li>
        <div class="caption center-align">
          <h3>This is our main Tagline!</h3>
          <h5 class="light grey-text text-lighten-3">Here's our secondary slogan.</h5>
        </div>
      </li>
      <li>
       
        <div class="caption left-align">
          <h3>Left Aligned Caption</h3>
          <h5 class="light grey-text text-lighten-3">Here's our secondary slogan.</h5>
        </div>
      </li>
      <li>
        
        <div class="caption right-align">
          <h3>Right Aligned Caption</h3>
          <h5 class="light grey-text text-lighten-3">Here's our secondary slogan.</h5>
        </div>
      </li>
      <li>
        <div class="caption center-align">
          <h3>This is our main Tagline!</h3>
          <h5 class="light grey-text text-lighten-3">Here's our secondary slogan.</h5>
        </div>
      </li>
    </ul>
  </div>
  </section>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/materialize/0.96.1/js/materialize.min.js'></script>

    <script src="js/index.js"></script>

</body>
</html>

Answer №1

Finally, the solution to my query has been discovered.

function moveForward(n){
 //$(".view-switcher").hide();
  if(n==1){
    $(".content-switcher").animate({
      "left":"-600px"
    },"slow");
  } else if(n==2){
    $(".content-switcher").animate({
      "left":"-1200px"
    },"slow");
  } else if(n==3){
    $(".content-switcher").animate({
      "left":"0px"
    },"slow");
  }
}
.container{
  width: 600px;
  margin: 0 auto;
  outline:1px solid red;
  overflow: hidden;
  background-image: url("https://static.vecteezy.com/system/resources/previews/000/093/696/original/vector-yellow-abstract-background.jpg");
}
.slider{ width: 1800px;}
.content-switcher{
  width: 600px;
  float: left;
  position: relative;
  top:0;
  left: 0;
}
<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Simple Content Slider</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>
  <div class="container">
  <a href="#" onclick="moveForward(1); return false;" style="color: #fff">Step 1</a>
  <a href="#" onclick="moveForward(2); return false;" style="color: #fff">Step 2</a>
  <a href="#" onclick="moveForward(3); return false;" style="color: #fff">Step 3</a>
  <div class="slider">
  <div class="content-switcher" id="content1">
    <p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
      . Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
      <img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437">
       <p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
      . Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
      <img src="http://vignette4.wikia.nocookie.net/mrmen/images/5/52/Small.gif/revision/latest?cb=20100731114437">
       <p>1Lorem ipsum dolor sit amet, consectetur adipisicing elit
      . Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
  </div>
  <div class="content-switcher" id="content2">
    <img src="http://images2.fanpop.com/image/user_images/Starmight350-808191_384_377.jpg">
    <p>2Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
  </div>
  <div class="content-switcher" id="content3">
    <p>3Lorem ipsum dolor sit amet, consectetur adipisicing elit. Saepe sint enim autem beatae sunt distinctio fugiat facilis accusamus dolorum labore quis natus culpa laudantium eos consequatur excepturi rerum error velit.</p>
  </div>
    </div>
</div>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

    <script src="js/index.js"></script>

</body>
</html>

Answer №2

To successfully address the quote issue in the section's style attribute, ensure that you avoid using double-quotes when declaring style="". This means eliminating any double-quotes within that specific attribute or substituting them with single quotes instead. Additionally, consider that using rgba(255,255,255,0) provides transparency, although a simpler method involves utilizing transparent. Alternatively, simply deleting that particular line is effective because by default there is no background, making it automatically transparent. For a functional demonstration, refer to this link - http://codepen.io/anon/pen/MJwOBR

Answer №3

To create an overlay effect on an image, you can use a div with the class "overlay" placed over the entire image like so:

Insert a div right after the <section> tag and give it the class name class="overlay"

<div class="overlay"></div>

Apply some CSS to position the overlay div on the image

.overlay
   {    
    position: absolute;
    height: 100%;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.17);
   }

Add CSS to properly display text

.caption {
position: relative;
z-index: 99;
}

Give this a try.

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

What is the best way to trigger a function exclusively upon clicking a particular element?

My goal is to enable the user to interact with the model by positioning cubes in space upon clicking the "Cubes Mode" button. I currently have a script from the three.js website that achieves this, but I want it to only run when the mentioned button is cli ...

Tips for keeping a floating action button visible at the bottom of the screen at all times

I am currently utilizing the Material UI framework. I have a floating action button that I would like to display in a specific position on the page without it moving when scrolling, and I am also wondering if this is a common issue. Below is the code sn ...

Tips for managing various potential return types in TypeScript?

In my research on the topic, I came across a discussion thread about obtaining the local IP address in Node.js at Get local IP address in Node.js. In that thread, there is a code snippet that I would like to incorporate: import net from 'net'; c ...

Align watermark content to the far left side

Having trouble getting my watermark to align properly on the left side of my website's main content. Here is how it currently looks: https://i.sstatic.net/Nfhh5.png The issue arises when I resize the screen or switch to mobile view, as the watermark ...

Selecting the correct data type for react-icons

I'm currently working on designing a navigation bar with a customized type to utilize the map() function. My goal is to display an icon for each entity, so that the icon appears in front of the text within the navbar. However, I am encountering diffic ...

How can I convert an Array into a Dictionary using JavaScript?

Is there a clever method (perhaps using a map function) to restructure my data object from this: [ {id: 1, from: "1/1/2021", to: "1/2/2022"}, {id: 2, from: "1/3/2021", to: "1/4/2022"}, {id: 1, from: "1/5/2 ...

featherlight.js - Execute code when modal is triggered

Situation with HTML <div id="form-lightbox"> <div class="form"> <div id="ajaxreplace"> <script type="text/javascript"> jQuery(function() { jQuery.ajaxReplace({ //parame ...

The for...of loop cannot be used with the .for property since it is not iterable. (Is

let arr = [{ category: 'music', views: 20 }, { category: 'abc', views: 32 }, { category: 'bob', views: 20 } ] for (const [key, value] of arr) { console.log(key, value) } console.log(Array ...

The error message "MongoDB encountered an issue with accessing the property 'push', as it was undefined."

Exploring node.js, express and MongoDB is a learning journey for me. While working on data association in MongoDB models, I encountered a runtime error. Even though the reference has been added to the model, the push() method fails to recognize it. Here ar ...

Demonstrate a array of values at varying angles within a circle using the functionalities of HTML5 canvas

Looking to utilize HTML5 Canvas and Javascript for a project where I need to showcase various values (depicted by dots possibly) at different angles within a circle. For example, data could include: val 34% @ 0°, val 54% @ 12°, val 23% @ 70°, a ...

Ways to determine the position of elements when they are centered using `margin:auto`

Is there a more efficient way to determine the position of an element that is centered using CSS margin:auto? Take a look at this fiddle: https://jsfiddle.net/vaxobasilidze/jhyfgusn/1/ If you click on the element with the red border, it should alert you ...

Customize the icon used for expanding and collapsing in AngularJS

I want to modify the icon (e.g., plus, minus) when clicking on an expand-collapse accordion. Currently, I am using the Font Awesome class for icons. While I know it can be easily achieved with jQuery, I'm wondering if there is a way to do this in Angu ...

Saving changes made in HTML is not supported when a checkbox is selected and the page is navigated in a React application using Bootstrap

In my array, there are multiple "question" elements with a similar structure like this: <><div className="row"><div className="col-12 col-md-9 col-lg-10 col-xl-10 col-xxl-10"><span>Question 1</span></div ...

Troubaling with AngularJS Routing issues

I am encountering an issue with my routing system. The "otherwise" case is functioning correctly, however, when I click on a menu item, the routing does not load the corresponding page automatically. Can someone assist me in identifying what is wrong with ...

What is the best method to ensure that an image remains at the bottom of a div even as the div's height adjusts?

In my current project, I am facing a challenge with positioning an image in the bottom-right corner of a dynamically changing div. Initially, this is easily achieved by using CSS selectors: #div1 { position: relative; } #div1 img { position: abso ...

The useEffect function is failing to execute, leading to an issue with an undefined variable

Attempting to retrieve a specific string with the help of useRouter, then utilizing that same string to access a particular document from Firebase is my current goal. This sequence of actions is supposed to take place within the confines of the useEffect f ...

Is there a way to define type information for a global variable when utilizing dynamic import within a function?

Here is a simplified version of my server code: server.ts import google from "googleapis"; const androidPublisher = google.androidpublisher("v3"); app.use('something', function(req, res, n){ ... }) ...(only one of the dozens of other meth ...

The variable from AJAX is not being displayed in PHP

Need help with transferring a JavaScript variable to the same PHP page. The following code is what I have so far: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script& ...

Learn how to create a disappearing dropdown menu in React that closes automatically when you select a specific category

I'm encountering an issue with a dropdown menu that remains visible on the screen even after selecting a specific category. The selected category is displayed in a box upon selection, but the dropdown menu doesn't disappear as intended. I am look ...

CSS image buttons are causing active_link_to list items to disappear when they become inactive

I'm struggling to get the nth css button/list elements to display correctly using active_link_to. The first css button appears without any problems and is active, but when I try to add new buttons to the list, they seem to disappear. HTML <li cla ...