jQuery传参

<a href="#" onClick="click_scroll('here1');">滚动到here1</a>
<a href="#" onClick="click_scroll('here2');">滚动到here2</a>
<script type="text/javascript">
function click_scroll(a) {
var e = $('#'+a);
var scroll_offset = e.offset();
$("body,html").animate({scrollTop:scroll_offset.top},300);
}
</script>

<div style="height:500px" ></div>
<div id="here1">点击后滚动到here1</div>
<div id="here2">点击后滚动到here2</div>

注意的是:函数内的$(this)是不可以用的;
posted @ 2016-05-10 14:23  子焱  阅读(491)  评论(0编辑  收藏  举报