Jquery滚动功能不工作
jquery scroll to function not working
我试图通过使用。parent,。next和。find来创建一个遍历页面的按钮,这是得到一个错误
Uncaught TypeError: Cannot read property 'top' of undefined
html: <div id="mainbody">
<div class="hero-unit">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
</div>
js:
/********************************
/ SCROLL TO NEXT
/*******************************/
$(document).ready(function(){
$('.next').on("click", function() {
var next;
next = $('#mainbody').parent().next().find(".index-block");
$('html,body').animate({ scrollTop: next.offset().top + 65}, 1000);
});
});
我对你的代码做了一些修改
HTML<div id="mainbody">
<div class="index-block hero-unit">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
<div class="index-block">
<div class="next"></div>
</div>
</div>
CSS .hero-unit, .index-block {
background-color: #efefef;
margin: 5px;
height: 200px;
position: relative;
width: 100%;
}
.next {
background-color: #333;
color: #FFF;
height: 50px;
width: 50px;
position: absolute;
bottom: 5px;
right: 5px;
cursor:pointer;
}
jQuery $(document).ready(function(){
$('.next').on("click", function() {
if($(this).parent().next(".index-block").offset() != undefined){
var next = $(this).parent().next(".index-block").offset();
$('html,body').animate({ scrollTop: next.top}, 1000);
}
});
});
相关文章:
- JavaScript打印功能使日历停止工作
- jQuery滚动功能只工作一次
- 为什么ng控制器不调用或工作或功能不工作
- 点击功能没有'ajax调用动态元素(Backbone)后无法工作
- AngularJs中的自动完成功能无法正常工作
- 为什么获胜'我的自定义功能工作
- 角度控制器功能赢得'不按指令工作
- 当我用鼠标左键点击时,让这个功能工作起来
- 重新启动游戏jQuery功能不工作
- 滚动功能不工作
- 角度控制器功能不;在指令内部调用时,似乎无法始终如一地工作
- JS不工作:Sublime 3编辑器-Var main=函数()-=不是“”;激活“;(功能新手)
- 单击水平滚动库中的图像以居中显示无法工作的功能
- MVC 分部视图中的 JQuery UI 自动完成功能只能工作一次
- 为什么本机浏览器排序功能的工作速度比快速排序慢
- 正在尝试获取此代码'在wordpress页面中工作的功能
- JavaScript:如何适应Firefox和/或Chrome的工作功能(IE)
- JQuery不工作.(功能)
- 无工作功能,具有ng-repeat
- 在角度方向don't控制器的工作功能