Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow down Rotating wheel before ending-Javascript

I am trying to do a rotating wheel(like Slot machine) based on this Link using swipe effect .

I have added a swipe(touch effect ) instead of button click ie when user swipes up, the wheel rotates.I have a trouble in making the wheel ending slowly.Since the entire code is very large,i am puting the main part here.Any ideas for making the rotation smooth and end slowly?

Note: Buttons in the page are dummy.

Next previous buttons are dummy

Updated : Live Url

Problem is When Swipe up speed increases before ending. Any ideas?

$("#carousel").swipe({
    //Generic swipe handler for all directions
    swipeUp: function (event, direction, distance, duration, fingerCount) {
        //console.log(event);
         if( duration >90 ){

                //console.log(carousel.rotation);
                //carousel.transform();

                var newvalue = 1;
                var addedInteval = carousel.theta * (carousel.panelCount-newvalue+1);
                var v;
                var interval = setInterval(function() {
                    var increment = parseInt( "-1");
                    carousel.rotation += (carousel.theta)* increment * -1;
                    carousel.transform();


                },100);


                setTimeout(function() {
                    clearInterval(interval);
                   carousel.rotation += ((360-carousel.rotation%360)+addedInteval);
                    console.log(carousel.rotation);
                    carousel.transform();
                }, 7000)
            }
    }
});
like image 708
Gopesh Avatar asked Nov 11 '22 18:11

Gopesh


1 Answers

Catch the window event of mouse wheel as

function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
    event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;

you can call your NEXT and PREVIOUS button event from the following code as

function handle(delta) {
        if (delta < 0)
             $('#Next').click();
        else
             $('#previous').click();
}

Check out this Fiddle

Courtesy from THIS

like image 106
Usman Avatar answered Nov 15 '22 04:11

Usman