0

The link below is for copy of a jquery slider , i want to make the sliding smooth but when I reduce the time in setinterval (say 200)the slider dont respond to the mouseup event instantaneously and the slides stop after a second or two after mouseup is triggered . I also tried using stop on jquery animation but that was not helpful . Here is the link . http://jsfiddle.net/WwT54/ For now after every half second the slide shifts by 10px , i want to make it look smooth .

$("#popUpInnerArrowLeft").mousedown(function (event) {

    movetoleft();
});

var into, into2;

function movetoleft() {
    function moveit() {
        $(".thumbsInnerContainer").animate({
            left: '-=10px'
        });
    }

    into = setInterval(function () {
        moveit();
    }, 500);

}

$(document).mouseup(function (event) {
    clearInterval(into);

});



//for the right arrow

$("#popUpInnerArrowRight").mousedown(function (event) {
    movetoright();
});

function movetoright() {

    function moveit2() {
        $(".thumbsInnerContainer").animate({
            left: '+=10px'
        });
    }

    into2 = setInterval(function () {
        moveit2();
    }, 500);

}

$(document).mouseup(function (event) {
    clearInterval(into2);
});

1 Answer 1

1

check this (is that what you want):

var into, into2, unit = '';

$("#popUpInnerArrowLeft").click(function (e) {  
    e.preventDefault();
    unit = false;
    movetoleft();
});

//for the right arrow
$("#popUpInnerArrowRight").click(function (e) {
    e.preventDefault();
    unit = true;
    movetoright();
});

function moveit() {    

    $(".thumbsInnerContainer").stop(true,true).animate({
        left: ((unit == true)? '+=':'-=') + '10px'
    },{easing:'linear'});
}

function movetoright() {        
    into = setInterval(function () {
        moveit();
    }, 300);
}

function movetoleft() {    
    into = setInterval(function () {
        moveit();
    }, 300);
}

$(document).mouseup(function (event) {
    clearInterval(into);    
});

working fiddle here: http://jsfiddle.net/WwT54/2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.