[Tutorial] Reputar em ajax
Página 1 de 1 • Compartilhe
- Zump
- Tempo Online : 33d 4h 43m 44s
Mensagens : 52
Reputação : 53
Autor: Zump
Funcionalidade: Em todas as versões
Crie um novo javascript com investimento nos tópicos com esse código:
- Código:
$(function(){
for (var vote = $('.vote'), i = 0, j = vote.length, bar, total, percent, n_pos, n_neg; i < j; i++) {
bar = $('.vote-bar', vote[i])[0];
if (bar) {
total = +bar.title.replace(/.*?\((\d+).*/, '$1');
percent = +bar.title.replace(/.*?(\d+)%.*/, '$1');
n_pos = Math.round(total * (percent / 100));
n_neg = total - n_pos;
} else {
n_pos = 0;
n_neg = 0;
}
vote[i].insertAdjacentHTML('afterbegin', '<span class="vote_num vote_good">' + n_pos + '</span>');
vote[i].insertAdjacentHTML('beforeend', '<span class="vote_num vote_bad">' + n_neg + '</span>');
$('a', vote[i]).click(function() {
var that = this,
links = $('a', that.parentNode);
$.get(that.href, function() {
var n = that[/minus/.test(that.className) ? 'nextSibling' : 'previousSibling'];
n.innerHTML = ++n.innerHTML;
links.fadeOut();
});
links.attr('href', '#').css({
opacity : 0.4,
cursor : 'default'
});
return false;
});
}
});
Resultado pode ser visto no fórum.
Tópicos semelhantes
Cria uma conta ou logue para postar uma mensagem.
Você precisa ser um membro, para poder postar uma resposta.
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos