Jquery color.js и Ajax - PullRequest
       3

Jquery color.js и Ajax

0 голосов
/ 05 августа 2011

Я создаю веб-сайт WordPress, где я добавляю случайный цвет к каждому фону поста.Код, который я использую ниже:

// Background color animation 
$(document).ready(function(){
    $(".texts").hover(function() {

    },function() {
        $(this).animate({ color: "#FFFFFF" }, 500);
    });

    // Fun with Color. Differnt font color each time hover
    // Original code can be found http://davidwalsh.name/jquery-random-color-animate
    original = $('.texts').css('background-color');

    $('.texts').hover(function() { //mouseover
        var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
        $(this).stop().animate({'backgroundColor': col}, 1000);
    },function() { //mouseout
        $(this).stop().animate({'backgroundColor': original},500);
    });

    $('.texts').hover(function() { //mouseover
        var col = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
        $(this).animate({'backgroundColor': col},500);
    },function() { //mouseout
        $(this).animate({'backgroundColor': col},500);
    });
});

Еще немного кода, где я использую Ajax для загрузки большего количества постов в коде домашней страницы:

var href = 'first';
$(document).ready(function() {
    $('#boxes').infinitescroll({
        navSelector : '.infinitescroll',
        nextSelector : '.infinitescroll a',
        itemSelector : '#boxes .box',
        loadingImg : '<?php echo get_bloginfo('stylesheet_directory') ?>/images/loading.gif',
        loadingText : 'Loading...',
        donetext : 'No more pages to load.',
        debug : false
    }, function(arrayOfNewElems) {
        $('#boxes').masonry('appended', $(arrayOfNewElems));
        if (href != $('.infinitescroll a').attr('href')) {
            href = $('.infinitescroll a').attr('href');
        }
    });
});

И проблема в том, чтопост страницы2 (после загрузки ajax) не может добавить класс jQuery к div.texts.

Как я могу это исправить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...