将CSS应用于正确放置的字母

时间:2012-07-18 10:10:55

标签: javascript jquery css drag-and-drop

目前,此代码在完成后将CSS样式应用于单词。我需要它将样式应用于单个字母以确定它们是否正确放置。

$(".drop").droppable({
drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));

    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            $('td[data-word=' + word + ']').addClass("wordglow2").fadeOut(1300);


        } else {
            $('td[data-word=' + word + ']').addClass("wordglow");

        }
    }
}
}); 

CSS是......

.wordglow {
    -webkit-box-shadow: inset 2px 2px 20px 7px #ff0000;
    box-shadow: inset 2px 2px 20px 7px #ff0000;

}

.wordglow2 {

    -webkit-box-shadow: inset 2px 2px 20px 7px #22ff22;
    box-shadow: inset 2px 2px 20px 7px #22ff22;

}

我试过这个但却没有快乐......

$(".drop").droppable({
drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));

    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            $('td[data-letter=' + word + ']').addClass("wordglow2").fadeOut(1300);


        } else {
            $('td[data-letter=' + word + ']').addClass("wordglow");

        }
    }
}
});

1 个答案:

答案 0 :(得分:1)

$(".drop").droppable({
drop: function(event, ui) {
    word = $(this).data('word');

    guesses[word].push($(ui.draggable).attr('data-letter'));
    console.log($(event).toString().toSource());
    console.log($(ui.draggable).text());

    console.log('CHECKING : ' + $(this).text() + ' against ' + $(ui.draggable).text().trim());


    if ($(this).text() == $(ui.draggable).text().trim()) {

        $(this).addClass('wordglow3');
    } else {
        $(this).addClass('wordglow');
    }
    console.log('CHECKING : ' + $(this).text() + ' against ' + $(ui.draggable).text().trim());


    console.log(guesses);

    if (guesses[word].length == 3) {
        if (guesses[word].join('') == word) {
            $('td[data-word=' + word + ']').addClass("wordglow2");

        } else {
            $('td[data-word=' + word + ']').addClass("wordglow4");

        }
    }


},

activate: function(event, ui) {
    word = $(this).data('word');

    // try to remove the class
    $('td[data-word=' + word + ']').removeClass('wordglow').removeClass('wordglow4').removeClass('wordglow3');
}


 });