我收到此錯誤信息:如何讓JavaScript函數在Rails應用程序中工作?
Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
,並且被標記的代碼第二條線
var nav = document.querySelector('.navv'),
nav_height = getComputedStyle(nav).height.split('px')[0],
我在一個靜態網頁轉換成on Rails應用程序一個Ruby的中間並且這段代碼在原始項目上工作得很好,但是我在Rails上收到了這條錯誤消息。我如何讓這段代碼再次工作?
下面是函數的做參考的其餘部分:
var nav = document.querySelector('.navv'),
nav_height = getComputedStyle(nav).height.split('px')[0],
nav_links = document.querySelector('.nav-links'),
//nav_links_height = getComputedStyle(nav_links).height.split('px')[0],
sticky_class = 'is-fixed';
//unfixed = 'unfixed'
function stickyScroll(e) {
if(window.pageYOffset > (nav_height)) {
nav_links.classList.add(sticky_class);
}
if(window.pageYOffset < (nav_height)) {
nav_links.classList.remove(sticky_class);
}
}
這與紅寶石在軌道上沒有任何關係。你應該刪除標籤。 – user1801879