Slide divs off screen using jQuery + added navigation arrows

▼魔方 西西 提交于 2019-12-11 13:48:04

问题


Can anyone help with adding navigation arrows to the code snippet found here

Slide a div offscreen using jQuery and the first answer given .... http://jsfiddle.net/jtbowden/ykbgT/2/

I want to be able to add direction arrows or prev/next links

Code below

html:

<div id="container">

    <div id="box1" class="box">Div #1</div>
    <div id="box2" class="box">Div #2</div>
    <div id="box3" class="box">Div #3</div>
    <div id="box4" class="box">Div #4</div>
    <div id="box5" class="box">Div #5</div>

</div>

css:

body {
    padding: 0px;    
}

#container {
    position: absolute;
    margin: 0px;
    padding: 0px;
    width: 100%;
    height: 100%;
    overflow: hidden;  
}

.box {
    position: absolute;
    width: 50%;
    height: 300px;
    line-height: 300px;
    font-size: 50px;
    text-align: center;
    border: 2px solid black;
    left: 150%;
    top: 100px;
    margin-left: -25%;
}

#box1 {
    background-color: green;
    left: 50%;
}

#box2 {
    background-color: yellow;
}

#box3 {
    background-color: red;
}

#box4 {
    background-color: orange;
}

#box5 {
    background-color: blue;
}

javascript:

$('.box').click(function() {

    $(this).animate({
        left: '-50%'
    }, 500, function() {
        $(this).css('left', '150%');
        $(this).appendTo('#container');
    });

    $(this).next().animate({
        left: '50%'
    }, 500);
});

It works brilliantly but navigation is one direction and activated by clicking the boxes

thanks in advance

aor


回答1:


Should be easy to do :)

make a "navigation control" wrapper element:

var $controller = $('<div class="control-wrapper" />);

add 2 main elements to act as left and right movement buttons:

var $left = $('<span class="move left" />').appendTo($controller),
    $right = = $('<span class="move right"/>').appendTo($controller);

add an event handler to each movement element for each animation:

$left.click(function(event) {
 ////MOVE THE NAV LEFT
};

$right.click(function(event) {
 ////MOVE THE NAV RIGHT
};

replace the comments with function calls to move the nav (you already have the logic to move it left ;) )

NOTE: Make sure you add "cursor: pointer" to the button element CSS classes so that they appear to be clickable to the user.




回答2:


If anyone is interested here is a more detailed answer for a similar question that works perfectly! jQuery animate divs on/off screen sequentially with navigation arrows



来源:https://stackoverflow.com/questions/13016392/slide-divs-off-screen-using-jquery-added-navigation-arrows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!