0
我抄代碼形式此示例屬性 '頂':http://codepen.io/senff/pen/ayGvD
粘菜單拋出遺漏的類型錯誤:無法讀取的不確定
我的JS:
$('.menu').addClass('original').clone().insertAfter('.menu').addClass('cloned').css('position','fixed').css('top','0').css('margin-top','0').css('z-index','500').removeClass('original').hide();
scrollIntervalID = setInterval(stickIt, 10);
function stickIt() {
var orgElementPos = $('.original').offset();
orgElementTop = orgElementPos.top;
if ($(window).scrollTop() >= (orgElementTop)) {
// scrolled past the original position; now only show the cloned, sticky element.
// Cloned element should always have same left position and width as original element.
orgElement = $('.original');
coordsOrgElement = orgElement.offset();
leftOrgElement = coordsOrgElement.left;
widthOrgElement = orgElement.css('width');
$('.cloned').css('left',leftOrgElement+'px').css('top',0).css('width',widthOrgElement).show();
$('.original').css('visibility','hidden');
} else {
// not scrolled past the menu; only show the original menu.
$('.cloned').hide();
$('.original').css('visibility','visible');
}
}
我的HTML:
<div id="intro-left">
<nav id="menu">
<ul class="navigation"><div class="menu-main-menu-container"><ul id="menu-main-menu" class="menu"><li id="menu-item-4" class="navlink menu-item menu-item-type-custom menu-item-object-custom current-menu-item menu-item-4"><a href="#home">HOME</a></li>
<li id="menu-item-8" class="navlink menu-item menu-item-type-custom menu-item-object-custom menu-item-8"><a href="#produkty">PRODUKTY</a></li>
<li id="menu-item-7" class="navlink menu-item menu-item-type-custom menu-item-object-custom menu-item-7"><a href="#realizacje">REALIZACJE</a></li>
<li id="menu-item-6" class="navlink menu-item menu-item-type-custom menu-item-object-custom menu-item-6"><a href="#onas">ONAS</a></li>
<li id="menu-item-5" class="navlink menu-item menu-item-type-custom menu-item-object-custom menu-item-5"><a href="#contact">KONTAKT</a></li>
</ul></div></ul></nav></div>
我的css:
#menu {
-moz-transition: all 250ms ease-out 0s;
-webkit-transition: all 250ms ease-out 0s;
-o-transition: all 250ms ease-out 0s;
-ms-transition: all 250ms ease-out 0s;
transition: all 250ms ease-out 0s;
position: fixed;
top: 0;
height: 1200px;
z-index: 900;
width: 84px;
background-color: rgba(17, 17, 17, 0.8);}
問題是它引發錯誤:Uncaught TypeError:無法讀取未定義的屬性'top'。
我能做些什麼來使它工作?
非常感謝提前。
我已經添加文件準備好,它使菜單消失。我沒有得到任何錯誤。它是Z指數問題? – Neko
你可以提供你的代碼jsfiddle。 –
我設法通過使用不同的代碼和交換位置絕對位置固定在內部左標籤中來設法使其工作。 – Neko