Skip to content

Instantly share code, notes, and snippets.

@rkmax
Last active December 25, 2015 13:39
Show Gist options
  • Save rkmax/6985722 to your computer and use it in GitHub Desktop.
Save rkmax/6985722 to your computer and use it in GitHub Desktop.
var mostrar_eventos = function() {
// [{titulo: "Evento 1", descripcion: "Descripcion Evento 1"},{titulo: "Evento 2", descripcion: "Descripcion Evento 2"}]
// Cada objeto puede tener muchos campos como fecha, url, image url, etc. el resto depende de tu necesidad e imaginacion
var eventos = {{eventos}}
,template_html = '<div class="left fecha">DATE</div><div class="left"><h4><a href="/eventos">TITLE</a></h4></div><div class="descripcion" style="display: none">DESCRIPTION</div>'
,$eventosContainer = $('#ticker_eventos')
html = []
;
for (var i = eventos.length - 1; i >= 0; i--) {
var evento = eventos[i];
// Asegurados hacer una copia y no una referencia para no modificar
// la plantilla original
html[i] = template_html + ''
// Remplazamos lo que queramos
html[i].replace('TITLE', evento.titulo);
html[i].replace('DESCRIPTION', evento.descripcion);
};
// Capturar el refreshId no es necesario si no vas a hacer nada con él
setInterval(function() {
$eventosContainer.fadeOut(1000, function() {
var $ticker = $(this);
var x = Math.floor((Math.random() * html.length) + 1);
$ticker.html(hmtl[x]);
$ticker.fadeIn(1000);
// Cuando hacemos click sobre todo entonces mostramos la descripcion
$ticker.on('click', function() {
$ticker.find('.descripcion').show();
});
});
}, 10000);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment