添加回到顶端 (Back To Top)

这个是点击了一个图片就会慢慢地回到顶端去的,可以直接点击我的部落格右下角的那张 Click 的图片直接查看效果

先到设计 --> 添加小工具 --> Html / Jave Script 把以下的代码放下去:

<script type= "text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
var scrolltotop={
   setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
    controlHTML: '<img src="图片网址" style="filter:alpha(opacity=70); -moz-opacity:0.1; width:100px; height:74px" />',
    controlattrs: {offsetx:0, offsety:0},
    anchorkeyword: '#top',
    state: {isvisible:false, shouldvisible:false},
    scrollup:function(){
        if (!this.cssfixedsupport)
            this.$control.css({opacity:0})
        var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
        if (typeof dest=="string" && jQuery('#'+dest).length==1)
            dest=jQuery('#'+dest).offset().top
        else
            dest=0
        this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
    },
    keepfixed:function(){
        var $window=jQuery(window)
        var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
        var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
        this.$control.css({left:controlx+'px', top:controly+'px'})
    },
    togglecontrol:function(){
        var scrolltop=jQuery(window).scrollTop()
        if (!this.cssfixedsupport)
            this.keepfixed()
        this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
        if (this.state.shouldvisible && !this.state.isvisible){
            this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
            this.state.isvisible=true
        }
        else if (this.state.shouldvisible==false && this.state.isvisible){
            this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
            this.state.isvisible=false
        }

    },
    init:function(){
        jQuery(document).ready(function($){
            var mainobj=scrolltotop
            var iebrws=document.all
            mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
            mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
            mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
                .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
                .attr({title:'Back to Top'})
                .click(function(){mainobj.scrollup(); return false})
                .appendTo('body')
            if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='')
                mainobj.$control.css({width:mainobj.$control.width()})
            mainobj.togglecontrol()
            $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
                mainobj.scrollup()
                return false
            })
            $(window).bind('scroll resize', function(e){
                mainobj.togglecontrol()
            })

        })
    }
}
scrolltotop.init()
</script>

注:把你的部落格往下移才会看到这个图片哦,一开始在顶端的时候不会出现的 =))

温馨小提示❤
红色的字 --> 图片的网址
黄色的字 --> 可自行更改
* Top - 上面
* Bottom - 下面
粉色的字 --> 可自行更改
 * Left - 左边
* Right - 右边

我自己制作了一些素材,喜欢可以拿去用哦 ^^

http://i1111.photobucket.com/albums/h468/Han_Er21/hellokitty.png
 http://i1111.photobucket.com/albums/h468/Han_Er21/8c4b337b.png
 http://i1111.photobucket.com/albums/h468/Han_Er21/top-1.png
 http://i1111.photobucket.com/albums/h468/Han_Er21/apple.png
 http://i1111.photobucket.com/albums/h468/Han_Er21/--.png
好了就可以保存起来啦 ~\(≧▽≦)/~

4 条评论:

留言规则 请勿犯规 :)

--------------------------------------------------------------------------------

1、由于评论太哆,有些我不能一一评论

2、如有捣乱着,恕我删除留言

3、有些博友要的教程,请勿再三询问,请到教程列表里仔细寻找

谢谢 :)