Friday 23 November 2012

Smooth Scrolling Go To Top Button For Blogger

Back to Top button or link is a link that sends your viewer to the top of page once clicked. This will help your readers navigate better, especially so if you have long pages.The best thing about this button is that it appears only when the user scrolls down the page and disappears as he scrolls up.We have kept the installation process a one step process. So that you can easily add this widget to your blog.

How To Add Scroll To Top Button To Blogger?


  • Go to Blogger > Design.
  • Click add a Gadget > HTML/JavaScript.
  • Paste the code and save it.



  • 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" >
    /*********************************************** 
    * Scroll To Top Control script- © Dynamic Drive DHTML code library undefinedwww.dynamicdrive.com) 
    * Modified by http://danish-mir.blogspot.com 
    * This notice MUST stay intact for legal use 
    * Visit Project Page at http://www.dynamicdrive.com for full source code 
    ***********************************************/
    var scrolltotop={ 
        //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control 
        //scrollto: Keyword undefinedInteger, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on undefined0=top). 
        setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
        controlHTML: '<img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhcnDnuecgBpvARIINxXX0Yn-19-Rt5olEvwuoHuN8XT-ocQvzHt5E-9lmDZTmDaL7M0dmpIFvNEL9KS_JqDTfMBWDP-YjOhqV0buUUHpWJAgf-fvd94lmxQ6dOUu2api4JOYl_0DPOHk/s1600/hb-arrow-up.png" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol" 
        controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner 
        anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
        state: {isvisible:false, shouldvisible:false},
        scrollup:functionundefined){ 
            if undefined!this.cssfixedsupport) //if control is positioned using JavaScript 
                this.$control.cssundefined{opacity:0}) //hide control immediately after clicking it 
            var dest=isNaNundefinedthis.setting.scrollto)? this.setting.scrollto : parseIntundefinedthis.setting.scrollto) 
            if undefinedtypeof dest=="string" && jQueryundefined'#'+dest).length==1) //check element set by string exists 
                dest=jQueryundefined'#'+dest).offsetundefined).top 
            else 
                dest=0 
            this.$body.animateundefined{scrollTop: dest}, this.setting.scrollduration); 
        },
        keepfixed:functionundefined){ 
            var $window=jQueryundefinedwindow) 
            var controlx=$window.scrollLeftundefined) + $window.widthundefined) - this.$control.widthundefined) - this.controlattrs.offsetx 
            var controly=$window.scrollTopundefined) + $window.heightundefined) - this.$control.heightundefined) - this.controlattrs.offsety 
            this.$control.cssundefined{left:controlx+'px', top:controly+'px'}) 
        },
        togglecontrol:functionundefined){ 
            var scrolltop=jQueryundefinedwindow).scrollTopundefined) 
            if undefined!this.cssfixedsupport) 
                this.keepfixedundefined) 
            this.state.shouldvisible=undefinedscrolltop>=this.setting.startline)? true : false 
            if undefinedthis.state.shouldvisible && !this.state.isvisible){ 
                this.$control.stopundefined).animateundefined{opacity:1}, this.setting.fadeduration[0]) 
                this.state.isvisible=true 
            } 
            else if undefinedthis.state.shouldvisible==false && this.state.isvisible){ 
                this.$control.stopundefined).animateundefined{opacity:0}, this.setting.fadeduration[1]) 
                this.state.isvisible=false 
            } 
        }, 
        
        init:functionundefined){ 
            jQueryundefineddocument).readyundefinedfunctionundefined$){ 
                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=undefinedwindow.opera)? undefineddocument.compatMode=="CSS1Compat"? $undefined'html') : $undefined'body')) : $undefined'html,body') 
                mainobj.$control=$undefined'<div id="topcontrol">'+mainobj.controlHTML+'</div>') 
                    .cssundefined{position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'}) 
                    .attrundefined{title:'Scroll Back to Top'}) 
                    .clickundefinedfunctionundefined){mainobj.scrollupundefined); return false}) 
                    .appendToundefined'body') 
                if undefineddocument.all && !window.XMLHttpRequest && mainobj.$control.textundefined)!='') //loose check for IE6 and below, plus whether control contains any text 
                    mainobj.$control.cssundefined{width:mainobj.$control.widthundefined)}) //IE6- seems to require an explicit width on a DIV containing text 
                mainobj.togglecontrolundefined) 
                $undefined'a[href="' + mainobj.anchorkeyword +'"]').clickundefinedfunctionundefined){ 
                    mainobj.scrollupundefined) 
                    return false 
                }) 
                $undefinedwindow).bindundefined'scroll resize', functionundefinede){ 
                    mainobj.togglecontrolundefined) 
                }) 
            }) 
        } 
    }
    scrolltotop.initundefined)
    </script>
    
    If you want to use your own image then just change the highlighted URL.

    No comments:

    Post a Comment