javascript - 结束前减速旋转轮-Javascript

标签 javascript jquery css 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)
            }
    }
});

最佳答案

捕捉鼠标滚轮的窗口事件为

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;

您可以通过以下代码调用您的NEXTPREVIOUS 按钮事件

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

看看这个 Fiddle

THIS 提供

关于javascript - 结束前减速旋转轮-Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20044844/

相关文章:

php - Jquery 按钮 OnClick 运行系统命令

javascript - 根据条件显示/隐藏

javascript - 如何使用 jquery 克隆选择对象

html - 父级内部的两个 div(它们之间有一个空格)

CSS Sprite 整页背景 : background-position

javascript - 以编程方式确定要放置在图像上的最佳前景色

javascript - jQuery多个id设置多个模式

javascript - 使用 Re-base 时 Firebase 在 React 中绑定(bind)和解除绑定(bind)

javascript - 防止焦点离开表单域

css - 给元素填充增加总宽度