[英]javascript selector with outerheight function isn't returning anything, and I can't select the selector anywhere else either
我一直在尝试在chrome开发工具中进行调试,但是topMenuHeight和scrollItems的变量始终为null或长度为0,因此为空。 实际上,一个变量只是$(selector).outerheight(),并且它返回null。 我绝对确定html ul具有正确的ID,无论如何,这是所有编码
因此,我们有了导航:
<nav>
<ul id="navmenu">
<li><a href="#splash"><i style="padding-right: 5px;" class="fa fa-home"></i>Home</a><div></div></li>
<li><a href="#about">Ordering</a><div></div></li>
<li><a href="#designs" target="_blank">Designs</a><div></div></li>
<li><a href="#hotels-resorts" target="_blank">Hotels / Resorts</a><div></div></li>
</ul>
</nav>
和一些js
var lastId,
topMenu = $("#navmenu"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }
});
和
var navHeight = $("#navmenu").outerHeight(true) ;
// Bind to scroll
$(window).scroll(function(){
// Get container scroll position
var fromTop = $(this).scrollTop()+navHeight;
我真的无法弄清楚,我在python上很擅长,但是据我所知,这个选择器应该可以工作了........
我检查并调试了您的网站。 你应该用
$(document).ready(function(){
//place your js here
});
嗨,当我检查您的网站时,您将
<script type="text/javascript" src="js/menu-scroll.js"></script>
在创建elemnet $(“#navmenu”)之前
所以它最初是空的
var navHeight = $("#navmenu").outerHeight(true) ;
变为空
在脚本上方添加脚本或在菜单滚动条中添加准备就绪的文档
$(document).ready(function(){
//place your js here
})
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.