jQuery offset() 在 Chrome 中返回 null
我有以下 HTML:
<div id="menu">
<ul>
<li><a href="#"><img src="imagenes/user.png" width="32" height="32" alt="My Profile" title=""/></a></li>
<li><a href="#"><img src="imagenes/photo.png" width="32" height="32" alt="Photo Gallery" title=""/></a></li>
<li><a href="#"><img src="imagenes/bookmark.png" width="32" height="32" alt="Social Bookmarking Tools" title=""/></a></li>
<li><a href="#"><img src="imagenes/rss.png" width="32" height="32" alt="RSS" title=""/></a></li>
<li><a href="#"><img src="imagenes/search.png" width="32" height="32" alt="Search" title=""/></a></li>
<li class="selected"><a href="#"><img src="imagenes/setting.png" width="32" height="32" alt="Control Panel" title=""/></a></li>
</ul>
<div id="box"><div class="head"></div></div></div>
和以下 JS 代码:
$(document).ready(function () {
var style = 'easeOutExpo';
var default_left = Math.round($('#menu li.selected').offset().left - $('#menu').offset().left);
var default_top = $('#menu li.selected').height();
...
我遇到的问题是“$('#menu li.selected').offset()”在 Chrome 中返回 null。我收到此错误消息:“未捕获类型错误:无法读取 null 的属性‘left’”。 在 Firefox 5.0 中工作正常,我还没有在 IE 中尝试过。
谢谢!
I have the following HTML:
<div id="menu">
<ul>
<li><a href="#"><img src="imagenes/user.png" width="32" height="32" alt="My Profile" title=""/></a></li>
<li><a href="#"><img src="imagenes/photo.png" width="32" height="32" alt="Photo Gallery" title=""/></a></li>
<li><a href="#"><img src="imagenes/bookmark.png" width="32" height="32" alt="Social Bookmarking Tools" title=""/></a></li>
<li><a href="#"><img src="imagenes/rss.png" width="32" height="32" alt="RSS" title=""/></a></li>
<li><a href="#"><img src="imagenes/search.png" width="32" height="32" alt="Search" title=""/></a></li>
<li class="selected"><a href="#"><img src="imagenes/setting.png" width="32" height="32" alt="Control Panel" title=""/></a></li>
</ul>
<div id="box"><div class="head"></div></div></div>
And the following JS code:
$(document).ready(function () {
var style = 'easeOutExpo';
var default_left = Math.round($('#menu li.selected').offset().left - $('#menu').offset().left);
var default_top = $('#menu li.selected').height();
...
The problem that I'm having is that "$('#menu li.selected').offset()" is returning null in Chrome. I'm getting this error message: "Uncaught TypeError: Cannot read property 'left' of null".
In Firefox 5.0 is working OK and I haven't tried in IE.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据上面的 HTML,
没有结束标记。
尝试在 HTML 末尾添加一个
。
Based on your HTML above,
<div id="menu">
does not have a closing tag.Try adding one more
</div>
to the end of your HTML.