javascript - Slide next previous anchor for each photos
问题描述
As you can see from the below JSFIDDLE link that the next and previous functions are working fine. It is taking the user to the next or previous photos accordingly. The issue what i am facing is when user reach to the very last photo by clicking next button and then if again he press "next" button then the function is getting freeze and doesn't work anymore until refresh the page again. This is happening for the first image also that user is on the first image and if clicks the "previous" button then the page gets freeze and the function is not working anymore. Kindly check the demo and any suggestions that how can i fix the issue?
https://jsfiddle.net/jpex4908/1/
var $jq = jQuery.noConflict();
$jq(document).ready(function($jq) {
var scrollTo = function(yoza) {
$jq('html, body').animate({
scrollTop: $jq(yoza).offset().top
}, 300);
};
$jq('.next').click(function(event) {
event.preventDefault();
var $jqcurrent = $jq('.home-block > .current');
if ($jqcurrent.index() != $jq('.home-block > div').length - 1) {
$jqcurrent.removeClass('current').next().addClass('current');
scrollTo($jqcurrent.next());
}
});
$jq('.prev').click(function(event) {
event.preventDefault();
var $jqcurrent = $jq('.home-block > .current');
if (!$jqcurrent.index() == 0) {
$jqcurrent.removeClass('current').prev().addClass('current');
scrollTo($jqcurrent.prev());
}
});
});
解决方案
推荐阅读
- ruby-on-rails - 覆盖 Rails eager_load 生成的连接
- go - 为什么这个布尔值没有在 Go 中注册?
- r - r ncdf4 "我找不到请求的变量!"
- python - 使用请求运行 python 程序并将请求发送到 docker 容器?
- react-native - 通过 forwardRef 传递 useAnimatedGestureHandler
- firebase - 如何使用 Flutter 检查 Firebase 中是否存在值?
- node.js - 使用 Native 而不是 Mongoose 创建一个基本的 MongoDB 包装器
- javascript - 数字旁边的正则表达式替换
- android-jetpack-compose - LaunchedEffect 在配置更改时执行,即使 rememberUpdatedState 没有改变
- java - 未调用 POST 请求的 RestTemplate