jQuery在ngView加载的元素[AngularJS]上找不到元素
jQuery cant find element on ngView loaded elements [AngularJS]
我正试图获取app.js控制的ngView
中存在的元素<div class='profile'></div>
的offset().top
,但控制台显示错误:
未捕获的类型错误:无法读取未定义的属性"top"
jQuery代码:
var topOfOthDiv = $('.profile').offset().top;
索引.ejs
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="main/js/main.js"></script>
...
</head>
<body>
<div class="ui inverted top fixed nbar hidden menu">...</div>
<div class="ui main container " ng-view>
</div>
</body>
main.js
$(document)
.ready(function() {
var topOfOthDiv = $('.profile').offset().top;
$(window).scroll(function() {
if($(window).scrollTop() > topOfOthDiv) { //scrolled past the other div?
$('.fixed.menu').transition('fade in'); //reached the desired point -- show div
}
if($(window).scrollTop() < topOfOthDiv) { //scrolled past the other div?
$('.fixed.menu').transition('fade out'); //reached the desired point -- show div
}
});
})
;
在ng-view
中,我加载了具有.profile
clssdiv的不同视图如果.profile
类位于index.ejs
如果不查看整个代码,我们就无法真正说出原因,因为这可能有很多原因,但最可能的原因是:
- 在声明
HTML
之后加载Javascript文件。这意味着脚本正在寻找在执行后写入浏览器的内容 - 您没有正确加载jQuery
相关文章:
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- AngularJS指令,在元素后插入HTML
- 使用AngularJS Directive WHITOUT$scope创建一个动态html元素
- angularjs删除动态形式元素中的特殊字符
- 从父元素AngularJS中获取多个输入字段的值
- 将持久活动类附加到导航栏范围中的导航元素(AngularJS)
- 展开/折叠树中的子元素(AngularJS)
- 来自Svc的数据未建模到视图元素AngularJS中
- 使用 Directives 注入 DOM 元素 AngularJS
- 获取元素angularJS的点击事件的html elemnt类型
- 从循环中隐藏元素(AngularJS)
- 真正阻止元素绑定-取消绑定元素-AngularJS
- jQuery在ngView加载的元素[AngularJS]上找不到元素
- CSS第n个子代不'无法处理动态隐藏元素[AngularJS]
- 如何防止父单击事件时,用户单击他的子元素?AngularJS
- 从列表中渲染输入中的特定元素——AngularJS
- $index的元素变化,而使用过滤器如何获得正确的索引元素angularjs
- 点击链接后滚动到不同模板上的特定元素(Angularjs)
- 点击body隐藏元素angularjs
- 选择/取消选择所有复选框元素AngularJS