滑动“卡片”效果 - 滑出,但不是

时间:2012-04-12 00:20:54

标签: javascript animation sliding-window

我正在使用以下代码创建一个滑动卡片效果,其中每个“卡片”是一个列表元素,它们在屏幕上滑动。它们仅在我设置的具有特定高度和宽度的“舞台”中可见。它工作得很好 - 除了卡片向左滑动很好,它们不会从右侧向内滑动。相反,它只是跳到页面上看起来有点令人吃惊。

有谁知道如何让下一个列表项从右边滑入而不是简单地出现?

谢谢!

JS:

window.addEvent('domready', function () {
    var totIncrement = 0;
    var increment = 968;
    var maxRightIncrement = increment * (-303); //this is -303 because there are 303 cards, but the example below only has 3
    var fx = new Fx.Style('slider-list', 'margin-left', {
        duration: 300,
        //transition: Fx.Transitions.Back.easeInOut,
        wait: true
    });
    // EVENTS for the button "previous"
    var pbuttons = document.getElementsByClassName('prevButton');
    for(i = 0; i < pbuttons.length; i++) {
        $(pbuttons[i]).addEvents({
            'click': function (event) {
                if(totIncrement > maxRightIncrement) {
                    totIncrement = totIncrement + increment;
                    fx.stop()
                    fx.start(totIncrement);
                }
            }
        });
    }
    //-------------------------------------
    // EVENTS for the button "next"
    // var buttons = $('.nextButton');
    var buttons = document.getElementsByClassName('nextButton');
    for(i = 0; i < buttons.length; i++) {
        $(buttons[i]).addEvents({
            'click': function (event) {
                if(totIncrement > maxRightIncrement) {
                    totIncrement = totIncrement - increment;
                    fx.stop()
                    fx.start(totIncrement);
                }
            }
        });
    }
});

HTML:

<div id="slider-stage">
    <ul id="slider-list">
        <li id="l1">
            <!-- previous button -->
            <div class="prev"><a class="prevButton" href="#">Previous</a></div>
            <div>
                <!-- content goes here -->
                <!-- next button -->
                <div class="slider-buttons">
                    <a class="nextButton" href="#">Next</a>
                </div>
            </div>
        </li>
        <li id="l2">
            <!-- previous button -->
            <div class="prev"><a class="prevButton" href="#">Previous</a></div>
            <div>
                <!-- content goes here -->
                <!-- next button -->
                <div class="slider-buttons">
                    <a class="nextButton" href="#">Next</a>
                </div>
            </div>
        </li>
        <li id="l3">
            <!-- previous button -->
            <div class="prev"><a class="prevButton" href="#">Previous</a></div>
            <div>
                <!-- content goes here -->
                <!-- next button -->
                <div class="slider-buttons">
                    <a class="nextButton" href="#">Next</a>
                </div>
            </div>
        </li>
    </ul>
</div>

0 个答案:

没有答案