2016-06-09 83 views
0

我正在试图制作一个网站,其中包含一个类似于http://presentation.creative-tim.com/的导航栏。当用户向下滚动页面时,我想让导航栏从透明变为颜色。jQuery的动画背景颜色在IE中不起作用

我正在使用Bootstrap和jQuery。我知道,jQuery不能为背景颜色制作动画。所以我使用jQuery颜色插件。 这是我的脚本:

$(document).ready(function() { 
$(window).scroll(function(){ 
    if ($(window).scrollTop() > 75){ 
     $('.navbar').stop().animate({'background-color': 'rgba(0, 128, 128, 1)'},400); 
    } 
    else if ($(window).scrollTop() < 75){ 
     $('.navbar').stop().animate({'background-color': 'rgba(0, 128, 128, 0)'},400); 
    } 
}); 
}); 

这是我的HTML:

<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 

 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
 
    <title>test</title> 
 
    <!-- Bootstrap --> 
 
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css"> 
 

 
</head> 
 

 
<body> 
 
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
 

 
    <!-- color animations--> 
 
    <script type="text/javascript" src="js/color2.js"></script> 
 
    <!-- Include all compiled plugins (below), or include individual files as needed --> 
 
    <script type="text/javascript" src="js/bootstrap.min.js"></script> 
 

 
    <nav class="navbar navbar-default navbar-fixed-top" style="background-color : rgba(0, 128, 128, 0); "> 
 
    <div class="container"> 
 
     <a class="navbar-brand" href="#" >Brand</a> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
     <li><a class="white" href="#">Blog</a> 
 
     </li> 
 
     <li><a class="white" href="#">Over ons</a> 
 
     </li> 
 
     <li><a class="white" href="#">Contact</a> 
 
     </li> 
 
     </ul> 
 

 

 
    </div> 
 
    </nav> 
 
</body> 
 

 
</html>

我坚持,现在这个问题了几天。我在这个网站上看到,加入$(document).ready可能会有所帮助,但它仍然无效。它在Chrome和Firefox中运行良好。但在IE中,导航栏保持透明。我无法在Google上找到答案。有谁知道如何解决它?

+0

您使用的是哪个版本的IE? – tektiv

+0

我在测试IE 11(赢得7)我要去尝试今晚 –

回答

0

我想通了。这是一个愚蠢的错误! IE 11限制了我的JavaScript的执行。

+0

有没有解决这个问题? – Acidic