0

クリックでコンテンツを変更するスライダーの年齢を探していましたが、これはまさに私がやろうとしていることです:

jQuery を使用して div を画面外にスライドさせる

しかし、何らかの理由で私はそれを機能させることができません。jsfiddle ページからコードをコピーしましたが、機能しません。私はおそらく超基本的な何かを台無しにしていますが、これが私のコードです:)

<style>
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: 50%;
top: 100px;
margin-left: -25%;
}

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

#box2 {
background-color: yellow;
}

#box3 {
background-color: red;
left: 150%;
}

#box4 {
background-color: orange;
left: 150%;
}

#box5 {
background-color: blue;
left: 150%;
}

</style>


<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>

</head>

<body>


<script type="text/javascript">

$('.box').click(function() {
$('.box').each( function() {
    if ($(this).offset().left < 0) {
        $(this).css("left", "150%");
    }
});

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

 if ($(this).next().size() > 0) {
     $(this).next().animate({
         left: '50%'
     }, 500);
 } else {
     $(this).prevAll().last().animate({
         left: '50%'
     }, 500);
 }
});j


</script>

<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>
4

2 に答える 2

1

あなたが置く必要があります:

   $(document).ready(function(){

<script type="text/javascript">

});

</script>

あなたのjqueryのバージョンは非常に古いです..

于 2013-06-09T10:27:43.137 に答える