2014-04-15 148 views
0

所以我有一个网站在2个不同的地方,并在1个网站上工作正常,另一方面,代码无法正常工作。即使我在浏览器中打开它也无法正常工作。为什么这个javascript不能在一个网站上工作,但在另一个网站上工作?

当某人将鼠标放在图像上时,该脚本应该将图像的不透明度从0.6 - > 1更改。现在它在原来的位置工作,在新的位置不工作,当我直接打开它时,它也不会在我的电脑上工作。

代码时间:

这是images.js

$(function() 
{ 
    $("#footer img").hover 
     (
     function() 
     { 
      $(this).stop().animate({"opacity": "1"}, "slow"); 
     }, 
     function() 
     { 
      $(this).stop().animate({"opacity": "0.6"}, "slow"); 
     } 
    ); 
}); 

这是对上述文件调用页面上的代码:

<script type="text/JavaScript" src="/_resources/javascript/images.js"></script> 

后来终于页脚的地方图像需要受到代码的影响:

<div id="footer"> 
<a href="completed-roofing-works/test.html"><img src="_resources/images/footer-3.jpg" alt="image 2" /></a> 
<a href="completed-roofing-works/completed-roofing-works-two.html"><img src="_resources/images/footer-6.jpg" alt="image 1" /></a> 
<a href="completed-roofing-works/test.html"><img src="_resources/images/footer-1.jpg" alt="image 3" /></a> 
<a href="testimonials/test.html"><img src="_resources/images/footer-4.jpg" alt="Roofers Kent" /></a><a href="testimonials/test.html"><img src="_resources/images/footer-2.jpg" alt="image 4" /></a> 
<a href="testimonials/test.html"><img src="_resources/images/footer-5.jpg" alt="image 5" /></a> 
</div></div> 

现在就坐在这里,我唯一能想到的就是Javascript没有安装,认为可能是这种情况?

谢谢。

:编辑:

看着它之后,我发现它可能是这个脚本以某种方式与它冲突:

<script language="javascript"> 

var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase())); 
      if (mobile) { 
       window.location.replace("mobile/choose.html"); 
      } 


    </script> 

它调用的代码后,可直接接触images.js文件

已解决的谢谢:

对于今后有类似问题的任何人:删除/在目录名前面,它似乎很不喜欢这个。

+1

它不工作是不够的,我们来帮助你。你有没有从调试器错误? –

+4

可能是* jQuery *不包括在内。 –

+0

可能是这两个网站引用了不同版本的jQuery? –

回答

2

你在那里的代码是jQuery。 jQuery是一个需要明确包含的库。

这与Vanilla JS不同,它非常好,浏览器已经提供它作为标准,多年来不需要任何激活或包含。

然而,在这种情况下,甚至香草JS是矫枉过正。

CSS:

#footer img { 
    opacity: 0.6; 
    transition: all 0.8s ease; 
} 
#footer img:hover { 
    opacity: 1; 
} 
相关问题