in this tutorial, you will learn about Materialize Material Box and sliders. Each and every concept is mentioned with the help of different examples.
Material box is basically a material design implementation of the lightbox plugin. Whenever, user clicks on the image then Material Box enlarge the image as well as center the image smoothly.
To create Materialize Box follow the following steps.
.materialboxed
class to the <img>
image element base class.
<img class="materialboxed" src="..." alt="Material Box">
//Javascript
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.materialboxed');
var instances = M.Materialbox.init(elems, options);
});
// Or with jQuery
$(document).ready(function(){
$('.materialboxed').materialbox();
});
General Syntax
<img class="materialboxed" src="..." alt="Material Box">
It is very easy to add a short caption to your photo. Just add the caption
as a data-caption attribute.
General Syntax
<img class="materialboxed" data-caption="Write down caption of the image" alt="Caption concept" >
Source Code
<img class="materialboxed" data-caption="This is a beautiful picture." src="../code-support/images/slider/bird.jpg" alt="Caption concept">
It is a simple and elegant image carousel that also contains captions that will be transitioned on their own depending on their alignment. It shows the slider indicators on the bottom of the slider.
To create Materialize Slider follow the following steps.
.slider
class to the slider container element i.e <div>
.
<div class="slider"></div>
.slides
class to the <ul>
element class and put it inside the slider container.
<div class="slider">
<ul class="slides"></ul>
</div>
<div class="slider">
<ul class="slides">
<li>
<img src=".." alt="Slider Image">
<div class="caption center-align">
<h3>Slider Heading</h3>
<h5 class="light grey-text text-lighten-3">Slider Sub Heading.</h5>
</div>
</li>
</ul>
</div>
//Javascript
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.slider');
var instances = M.Slider.init(elems, options);
});
// Or with jQuery
$(document).ready(function(){
$('.slider').slider();
});
Source Code
<div class="slider">
<ul class="slides">
<li>
<img src="https://lorempixel.com/580/250/nature/1"> <!-- random image -->
<div class="caption center-align">
<b>This is our big Tagline!</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
<li>
<img src="https://lorempixel.com/580/250/nature/2"> <!-- random image -->
<div class="caption left-align">
<b>Left Aligned Caption</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
<li>
<img src="https://lorempixel.com/580/250/nature/3"> <!-- random image -->
<div class="caption right-align">
<b>Right Aligned Caption</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
<li>
<img src="https://lorempixel.com/580/250/nature/4"> <!-- random image -->
<div class="caption center-align">
<span>This is our big Tagline!</span>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
</ul>
</div>
You can easily make full screen slider by adding the fullscreen
class to the slider div having .slider
class.
General Syntax
<div class="slider fullscreen">
<ul class="slides"></ul>
</div>
Source Code
<div class="slider fullscreen">
<ul class="slides">
<li>
<img src="../code-support/images/slider/bird.jpg"> <!-- random image -->
<div class="caption center-align">
<b>This is our big Tagline!</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
<li>
<img src="../code-support/images/slider/lily.jpg"> <!-- random image -->
<div class="caption left-align">
<b>Left Aligned Caption</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
<li>
<img src="../code-support/images/slider/rose.jpg"> <!-- random image -->
<div class="caption right-align">
<b>Right Aligned Caption</b>
<p class="light grey-text text-lighten-3">Here's our small slogan.</p>
</div>
</li>
</ul>
</div>