Decide which content should be come with role effect, and put the head lines inside the <div> tag like below
<div class="wrapper">
<div class="roles">
<div>
Google Mobile
</div>
<div>
Micromax Mobile
</div>
<div>
Nokia Mobile
</div>
<div>
I am an aspiring individual.
</div>
<div>
Android OS
</div>
</div>
</div>
We are using the following CSS for given style.
body {
background: #f1f1f1;
color: #222;
font-family: 'Open Sans', sans-serif;
}
.wrapper {
padding: 100px;
width: 500px;
display: block;
text-align: center;
margin: 0 auto;
}
.roles {
font-size: 30px;
height: 50px;
vertical-align: middle;
overflow: hidden;
}
.roles div {
height: 50px;
transition: margin-top 1s ease-in-out;
}
The Javascript Code is shown below
var current = 1; //keeps track of the current div
var height = $('.roles').height(); //the height of the roles div
var numberDivs = $('.roles').children().length; //the number of children of the roles div
var first = $('.roles div:nth-child(1)'); //the first div nested in roles div
setInterval(function() {
var number = current * -height;
first.css('margin-top', number + 'px');
if (current === numberDivs) {
first.css('margin-top', '0px');
current = 1;
} else current++;
}, 2000);
Example Program:- (Editor)
Editor is Loading...
Advertisement
0 comments:
Post a Comment