簡體   English   中英

為什么此javascript無法在一個站點上運行,而在另一個站點上運行呢?

[英]Why won't this javascript work on one site, but does on another?

因此,我在兩個不同的地方都有一個網站,在一個網站上它可以正常工作,在另一個網站上,代碼無法正常工作。 即使在瀏覽器中打開它,它也無法正常工作。

當有人將鼠標懸停在圖像上時,該腳本應該將圖像的不透明度從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文件的代碼之后

解決了謝謝您:

對於以后遇到類似問題的任何人:刪除目錄名稱前的/,看起來似乎非常不喜歡它。

您所擁有的代碼是jQuery。 jQuery是一個需要顯式包含的庫。

這與Vanilla JS相反,后者非常好,以至於瀏覽器多年來一直作為標准提供它,而無需任何激活或包含。

但是,在這種情況下,甚至Vanilla JS都不過分。

CSS:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM