给主题增加滑动效果(gotoup)
今天把导航栏固定了,想起增加滑动效果使之能够滚动到网页上部或下部。嘿嘿!不过在Google那搜索了一下。找了很久还是没找到,后来偶然的情况下发现了 xiaorsz写的文章,不过太复杂了,然后转到了popdo那里。发现这个方法简单!就用了这个方法!我是在footer.php最底下加入这个代码
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
<script type="text/javascript">
$(document).ready(function(){
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target
|| $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
});
</script>
在页面需要的地方中加入以下代码:(链接方式为#加ID名称)
<div id="gotop"><a href="#header">Top</a></div>
<div id="godown"><a href="#footer">Down</a></div>
<div id="godown"><a href="#footer">Down</a></div>
这个代码可以实现留言转向!
接下来就是css了自己写吧,我就不说明了!
当然了还有留言也此有效果,不过在Opera上向上的没有滚动效果,不过还是能够链接过去.
| anyShare分享到: | |
| |
发表评论 | Trackback 0 条评论.
