Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Jquery为twitch状态添加动画CSS类_Jquery_Html_Css_Twitch - Fatal编程技术网

使用Jquery为twitch状态添加动画CSS类

使用Jquery为twitch状态添加动画CSS类,jquery,html,css,twitch,Jquery,Html,Css,Twitch,我试图根据我的twitch状态是否为live,在元素上添加css样式。有点像灯塔。我似乎无法将css样式添加到对象中。如果我直接在html中添加动画样式属性,它确实可以工作,但需要根据twitch状态将其包装在if语句中。下面是位于我的标题中的脚本代码 <script type='text/javascript'> $(document).ready(function() { // Check GRG's twitch status - uses css keyframes to p

我试图根据我的twitch状态是否为live,在元素上添加css样式。有点像灯塔。我似乎无法将css样式添加到对象中。如果我直接在html中添加动画样式属性,它确实可以工作,但需要根据twitch状态将其包装在if语句中。下面是位于我的标题中的脚本代码

<script type='text/javascript'>
$(document).ready(function() {
// Check GRG's twitch status - uses css keyframes to pulse colors if live 
    $.getJSON('https://api.twitch.tv/kraken/streams/grimreapergamers', function(channel) {
        if (channel['stream'] === null) { 
            $('fa fa-twitch').css('animation','twitchpulse 4s infinite');
        } else {
            $('fa fa-twitch').css("style","animation:twitchpulse 4s infinite");
        }
    });
}}
</script>
</head>

$(文档).ready(函数(){
//检查GRG的twitch状态-如果活动,则使用css关键帧脉冲颜色
$.getJSON('https://api.twitch.tv/kraken/streams/grimreapergamers,函数(通道){
如果(通道['stream']==null){
$('fa-fa-twitch').css('animation','twitchpulse 4s-infinite');
}否则{
$('fa-fa-twitch').css(“风格”,“动画:twitchpulse 4s无限”);
}
});
}}
这是我试图修改的带有css类的HTML行

<a class="dow-menu" href="http://www.twitch.tv/grimreapergamers" target="_blank" data-toggle="tooltip" data-original-title="Twitch">
    <i class="fa fa-twitch"></i>
</a>


我在JSFIDLE中也有代码。

您的选择器应该有
来识别类元素。不提供点,将搜索
fa
fa-twitch
标记名

$('fa fa-twitch')
应该是

$('.fa.fa-twitch')
因为这两个类位于同一个选择器上。您编写的方法将尝试查找具有class
fa-twitch

还要确保您的代码在
dom ready


谢谢,我看到它在工作。如果我将if语句添加回检查json提要,它将停止工作。为此,您可能需要放置一个调试点,并检查
频道
的外观。无需担心。json提要上jfiddle中的跨原点错误