首页 > 解决方案 > 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());
        }
    });
});

标签: javascriptjqueryhtml

解决方案


推荐阅读