在结束之前减慢旋转轮-Javascript

时间:2013-11-18 09:57:48

标签: javascript jquery css3 carousel

我正在尝试使用滑动效果根据此Link进行旋转轮(如老虎机)。

我添加了一个滑动(触摸效果)而不是按钮点击,即当用户向上滑动时,滚轮旋转。我在制作轮子结束时遇到了麻烦。由于整个代码非常大,我正在放置部分在这里。任何使旋转平滑并缓慢结束的想法?

注意:页面中的按钮是假的。

下一个上一个按钮是虚拟的

更新: Live Url

问题是在结束前向上滑动速度增加。有什么想法吗?

$("#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)
            }
    }
});

1 个答案:

答案 0 :(得分:1)

抓住鼠标滚轮的窗口事件

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;

您可以通过以下代码调用 NEXT PREVIOUS 按钮事件

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

查看此Fiddle

来自THIS

的礼貌