我有这个HTML
<div id="container">
<div id="slide">
<div id="slide1">
Content 1
<a href="#" id="show-slide2">Show Content 2</a>
</div>
<div id="slide2">
Content 2
</div>
</div>
</div>
#container
有max-width:1250px
。仅显示Onload #slide1
。现在我想点击a#show-slide2
,#slide2
应该从右边滑入。
我需要什么CSS和JS?
答案 0 :(得分:2)
的 LIVE DEMO 强>
HTML
<div id="slides">
<div>
Content 1
<a href="#" id="show-slide2">Show Content 2</a>
</div>
<div>
Content 2
</div>
</div>
CSS:
#slides{
position:relative;
overflow:hidden;
margin:0 auto;
background:#cf5;
width:400px;
height:200px;
white-space:nowrap;
}
#slides div{
position:relative;
display:inline-block;
margin-right:-4px;
white-space:normal;
vertical-align:top;
*display:inline;
background:#eee;
width:400px;
height:200px;
}
jQuery的:
$(function(){
var slideW = $('#slides').width();
$('#show-slide2').click(function( e ){
e.preventDefault();
$('#slides').animate({scrollLeft: slideW }, 600);
});
});