如何使用jQuery更改文本的颜色

时间:2014-05-26 22:51:54

标签: jquery

我刚刚开始学习jQuery,并且当用户滚动时我试图改变我网页上的一段文字的颜色。这段文字包含在div id中。我在CSS表格中使用的div的名称是#headerTitle。

这是我到目前为止的代码:

$(document).ready(function(){

    $(window).scroll(function(){

        $("#headerTitle").backgroundColor({
            transition:"background-color": "green"
         });
    }   
}

1 个答案:

答案 0 :(得分:2)

这样做:

   $(document).ready(function () {
    $(window).scroll(function () {
        alert('The Window Scrolled');
        // Set the color attribute on the div
        $('#headerTitle').css('color', 'red');
    });
   });

当窗口滚动时,您会被“警告”(这确保它可以正常工作,您可以删除),然后它将使用jQuery CSS方法在您的div中设置text颜色。