The Chef
07-10-2012, 11:16 PM
I pulled a simple Javascript snippet that performs a simple fade in/out quote rotator.
Here is a demo of it: Demo (http://www.vijayjoshi.org/examples/textRotator.html)
Right now it runs through the quotes as I input them by use of DIVs
<div id="quotes">
<div>Before turning to those moral and mental aspects of the matter which
present the greatest difficulties, let the inquirer begin by mastering
more elementary problems.
</div>
<div>How often have I said to you that when you have eliminated the
impossible, whatever remains, however improbable, must be the truth?
</div>
</div>
Here is the Javascript that runs it:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/
jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
setupRotator();
});
function setupRotator()
{
if($('.textItem').length > 1)
{
$('.textItem:first').addClass('current').fadeIn(1000);
setInterval('textRotate()', 3000);
}
}
function textRotate()
{
var current = $('#quotes > .current');
if(current.next().length == 0)
{
current.removeClass('current').fadeOut(1000);
$('.textItem:first').addClass('current').fadeIn(1000);
}
else
{
current.removeClass('current').fadeOut(1000);
current.next().addClass('current').fadeIn(1000);
}
}
</script>
How can I modify this script to make it pull a quote randomly?
I tried changing current.next() to current.Math.random() but no luck.
Thanks for the help!
Here is a demo of it: Demo (http://www.vijayjoshi.org/examples/textRotator.html)
Right now it runs through the quotes as I input them by use of DIVs
<div id="quotes">
<div>Before turning to those moral and mental aspects of the matter which
present the greatest difficulties, let the inquirer begin by mastering
more elementary problems.
</div>
<div>How often have I said to you that when you have eliminated the
impossible, whatever remains, however improbable, must be the truth?
</div>
</div>
Here is the Javascript that runs it:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/
jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
setupRotator();
});
function setupRotator()
{
if($('.textItem').length > 1)
{
$('.textItem:first').addClass('current').fadeIn(1000);
setInterval('textRotate()', 3000);
}
}
function textRotate()
{
var current = $('#quotes > .current');
if(current.next().length == 0)
{
current.removeClass('current').fadeOut(1000);
$('.textItem:first').addClass('current').fadeIn(1000);
}
else
{
current.removeClass('current').fadeOut(1000);
current.next().addClass('current').fadeIn(1000);
}
}
</script>
How can I modify this script to make it pull a quote randomly?
I tried changing current.next() to current.Math.random() but no luck.
Thanks for the help!