我有一个词汇表页面,可以使用锚点。当您点击“A”链接时,它会转到#A,当您点击“B”时,它会转到“#B”。但这会跳到锚点,我希望它滚动。
我怎么能做这个宽度javascrit?我可以在html onclick上放一个javascript吗?
这是我的实际代码:
<?php $categories = get_categories('child_of=100&hide_empty=0');
foreach ($categories as $category) {
//Display the sub category information using $category values like $category->cat_name
echo '<h2><a name="' . $category->name . '">'.$category->name.'</a></h2>';
echo '<ul>';
$posts = get_posts(array('cat' => $category->term_id, 'order' => 'ASC', 'post_type' => 'glosario', 'showposts' =>-1, 'post_status' => 'publish,future,draft'));
foreach ($posts as $post) {
echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';
}
echo '</ul>';
} ?>
<div id="scrollablemenu">
<?php $cats = get_categories( 'child_of=100&hide_empty=0');
foreach ($cats as $cat) {
echo '<a href="#' . $cat->cat_name . '" class="scrollablemenubutton" class="scroll">' . $cat->cat_name . '</a>';
}
?>
jQuery(document).ready(function() {
jQuery(".scroll").click(function(event){
event.preventDefault();
$('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
});
});
谢谢!