我想实现下一个行为: 当我点击链接到锚点时 - 目标div应该重新定位在他的容器顶部顶部(如果需要,应该增加容器的高度)。 这是一个“html / css - draft” - http://jsfiddle.net/k2dGD/
请用javascript帮我。
HTML:
<div class="triggers">
<a href="#one">One</a>
<a href="#two">Two</a>
<a href="#three">Three</a>
<a href="#four">Four</a>
<a href="#five">Five</a>
</div>
<div class="blocks">
<div id="one" class="block">
BLOCK ONE --- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem exercitationem dolores officiis omnis nostrum molestiae quo laboriosam iure placeat velit sit porro illum eius repellendus suscipit nemo dignissimos! Delectus atque.
</div>
<div id="two" class="block">
BLOCK TWO --- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem exercitationem dolores officiis omnis nostrum molestiae quo laboriosam iure placeat velit sit porro illum eius repellendus suscipit nemo dignissimos! Delectus atque.
</div>
<div id="three" class="block">
BLOCK THREE --- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem exercitationem dolores officiis omnis nostrum molestiae quo laboriosam iure placeat velit sit porro illum eius repellendus suscipit nemo dignissimos! Delectus atque.
</div>
<div id="four" class="block">
BLOCK FOUR --- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem exercitationem dolores officiis omnis nostrum molestiae quo laboriosam iure placeat velit sit porro illum eius repellendus suscipit nemo dignissimos! Delectus atque.
</div>
<div id="five" class="block">
BLOCK FIVE --- Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem exercitationem dolores officiis omnis nostrum molestiae quo laboriosam iure placeat velit sit porro illum eius repellendus suscipit nemo dignissimos! Delectus atque.
</div>
</div>
答案 0 :(得分:0)
$(function(){
$('.triggers a').click(function(){
var $item = $( $(this).attr('href') );
$(this).closest('div').next('.blocks').prepend( $item );
});
});