我收到此错误信息:如何让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