JSFiddle - React, Tailwind, and code Playground
by Chris_Happy
HTML
<section class="marquee">
<div class="marquee-wrapper">
<div class="marquee-content">
Updates: Update (8 Mar 2016): Now plugin have new option: startVisible The marquee will be visible in the start if set to true. Thanks to @nuke-ellington 👠Update (24 Jan 2014): Note: people who been asking me how to use this plugin with content being
loaded with Ajax, please read notes about this update. New methods added, so now after you start the plugin using var $mq = $('.marquee').marquee();, you start the plugin using var $mq = $('.marquee').marquee();, you start the plugin using var $mq
= $('.marquee').marquee();, then you can pause, resume, togglepause, resume) and desestroy destroy toggle(pause, resume) and destroy toggle(pause, resume) and destroy methods e.g to remove the marquee plugin from your element simply use $mq.marquee('destroy');.
Similarly you can use pause the marquee any time using $mq.marquee('pause');.
</div>
</div>
</section>
CSS
.marquee {
margin: auto;
width: 600px;
height: 200px;
overflow: auto;
position: relative;
}
.marquee-wrapper { position: absolute; }
.marquee-content {
margin: 0;
padding: 30px 0;
}
JavaScript
//Cache values
$wrap = $(".marquee-wrapper")
$con = $(".marquee-content");
cHeight = $con.outerHeight(true)
if ($(".marquee").height() < cHeight) {
$con.clone().appendTo( $wrap );
}
function animate() {
$wrap.animate({
top: "-=" + cHeight //minus height from the value of top
},
3000, // milisecs of animations length
"linear", // type of animations
function() { //function to run after animation is complete
$(this).css("top", "0");
animate();
});
}
animate(); //Run function in the beginning