JavaScript 外部檔案中的相對路徑
使用外部包含的 JavaScript 檔案時,了解相對路徑的工作原理非常重要。
在所提供的場景中,將 JavaScript 檔案部署到虛擬目錄中的伺服器時會出現問題。與本機開發環境不同,JavaScript 檔案中的背景影像路徑變得不準確。
要解決此問題,重要的是要認識到外部 JavaScript 檔案中的路徑與它們所在的頁面相關,而不是 JavaScript 檔案的實體位置。這意味著需要根據頁面在伺服器上的位置來調整路徑。
建議的解決方案是使用 JavaScript 變數來定義映像引用的基本路徑。可以以無論部署位置如何都保持一致的方式設定此變數。
例如,可以在
中宣告一個名為 imagePath 的變數。儲存基本路徑的頁面部分:<script type="text/javascript"> var imagePath = 'http://sstatic.net/so/img/'; </script>
然後,在外部JavaScript 檔案中,可以修改影像的路徑以引用imagePath 變數:
$("#toggle").click(function() { if (left.width() > 0) { AnimateNav(left, right, 0); $(this).css("background", "url(" + imagePath + "filters_expand.jpg)"); } else { AnimateNav(left, right, 170); $(this).css("background", "url(" + imagePath + "filters_collapse.jpg)"); } });
透過定義
中的imagePath 變數部分,它變得易於管理並確保跨不同部署場景的映像路徑一致。以上是部署後如何處理外部JavaScript檔案中映像的相對路徑?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

是的,youshouldlearnbothflexboxandgrid.1)flexboxisidealforone-demensional,flexiblelayoutslikenavigationmenus.2)gridexcelstcelsintwo-dimensional,confffferDesignssignssuchasmagagazineLayouts.3)blosebothenHancesSunHanceSlineHancesLayOutflexibilitibilitibilitibilitibilityAnderibilitibilityAndresponScormentilial anderingStruction

重構自己的代碼看起來是什麼樣的?約翰·瑞亞(John Rhea)挑選了他寫的一個舊的CSS動畫,並介紹了優化它的思維過程。

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframesispopularduetoitsversatoryand and powerincreatingsmoothcsssanimations.keytricksinclude:1)definingsmoothtransitionsbetnestates,2)使用AnimatingMultatingMultationMultationProperPertiessimultane,3)使用使用4)使用BombingeNtibalibility,4)使用CombanningWiThjavoFofofofoftofofo

CSSCOUNTERSAREDOMANAGEAUTOMANAMBERINGINWEBDESIGNS.1)他們可以使用forterablesofcontents,ListItems,and customnumbering.2)AdvancedsincludenestednumberingSystems.3)挑戰挑戰InclassINCludeBrowsEccerCerceribaliblesibility andperformiballibility andperformissises.4)創造性

使用滾動陰影,尤其是對於移動設備,是克里斯以前涵蓋的一個微妙的UX。傑夫(Geoff)涵蓋了一種使用動畫限制屬性的新方法。這是另一種方式。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

禪工作室 13.0.1
強大的PHP整合開發環境

WebStorm Mac版
好用的JavaScript開發工具

SublimeText3漢化版
中文版,非常好用