2

任何人都可以帮助在此处找到的代码片段中添加导航箭头

使用 jQuery 将 div 滑出屏幕 并给出第一个答案.... http://jsfiddle.net/jtbowden/ykbgT/2/

我希望能够添加方向箭头或上一个/下一个链接

下面的代码

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);
});

它工作得很好,但导航是一个方向,通过单击框激活

提前致谢

奥尔

4

2 回答 2

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.

于 2012-10-22T17:48:01.893 回答
0

如果有人对此感兴趣,可以为类似的问题提供更详细的答案,而且效果很好!jQuery 动画 div 使用导航箭头按顺序打开/关闭屏幕

于 2013-09-16T09:56:08.057 回答