jquery - .动画({'left' : '0%' }); not working when attached to 3 divs?

标签 jquery html css

我有下面的代码,它在点击图像时在 div 之间滑动。

问题是,我希望能够像这样滑动:红色 > 绿色 > 蓝色,但目前我只能在红色和绿色 div 之间滑动。

谁能给我一些指导吗?

谢谢!

/* These are the individual divs which are scrolled through */
#left {
    min-width:100%;
    min-height:300px;
    background:red;
    position:absolute;
    top: 0;
    left:0;
}
#right {
    min-width:100%;
    min-height:300px;
    background:blue;
    position:absolute;
    top: 0; 
    right:-105%;
}
#middle {
    min-width:100%;
    min-height:300px;
    background:green;
    position:absolute;
    top: 0;
    right:-205%;
}

JS/JQuery:

<script>
    $(document).ready(function() {

    //Scroll all content to the left <---- this way
    $('#scrollRight').click(function(e) {  

            $('.container').animate({'left': '-105%'});             

        });

        //Scroll all content to the right ----> this way
    $('#scrollLeft').click(function(e) {  
    $('.container').animate({'left': '0%'});        

        });         

    //End document ready function.      
    });
    </script>

HTML:

<div class="container"> 
            <!-- You have to add the last div first, so that each div will get added after that...basically so that the div you wich to see first, is in first position -->

            <div id="right">right scroll</div>  
            <div id="middle">left scroll</div>          
            <div id="left">left scroll</div>

    </div>

这是 fiddle :

http://jsfiddle.net/45g3Le59/

最佳答案

所有三个 DIVS 同时进行动画处理,因此您只会看到两张幻灯片进行动画处理...在动画之间添加延迟。

关于jquery - .动画({'left' : '0%' }); not working when attached to 3 divs?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26106171/

相关文章:

javascript - 如何在 window.setInterval 中每分钟运行一次 getJSON 函数?

jQuery 不区分大小写包含选择器 - 1.8.1

jquery - 图像未在 IE 中呈现

javascript - 如何用JS获取日期?

css - 网站在水平 iPhone 方向上未正确居中

javascript - 在 Twitter Bootstrap 3 中验证导航

css - 链接到 LESS css 时拒绝访问受限 URI

php - 在第一个输入值之后填充另一个输入字段值

php - ajax表单提交与jquery多个表单

JavaScript 调整