Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  2. <script type='text/javascript' language='Javascript'>
  3. var scrolltotop={
  4. //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
  5. //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (1=top).
  6. setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
  7. controlHTML: '<img src="GIF OU IMAGEM PARA SUBIR AO TOPO"/>', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
  8. controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ center of window corner
  9. anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
  10. state: {isvisible:false, shouldvisible:false},
  11. scrollup:function(){
  12. if (!this.cssfixedsupport) //if control is positioned using JavaScript
  13. this.$control.css({opacity:0}) //hide control immediately after clicking it
  14. var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
  15. if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
  16. dest=jQuery('#'+dest).offset().top
  17. else
  18. dest=0
  19. this.$body.animate({scrollTop: dest}, this.setting.scrollduration);
  20. },
  21. keepfixed:function(){
  22. var $window=jQuery(window)
  23. var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
  24. var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
  25. this.$control.css({left:controlx+'px', top:controly+'px'})
  26. },
  27. togglecontrol:function(){
  28. var scrolltop=jQuery(window).scrollTop()
  29. if (!this.cssfixedsupport)
  30. this.keepfixed()
  31. this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
  32. if (this.state.shouldvisible && !this.state.isvisible){
  33. this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
  34. this.state.isvisible=true
  35. }
  36. else if (this.state.shouldvisible==false && this.state.isvisible){
  37. this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
  38. this.state.isvisible=false
  39. }
  40. },
  41. init:function(){
  42. jQuery(document).ready(function($){
  43. var mainobj=scrolltotop
  44. var iebrws=document.all
  45. mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
  46. mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
  47. mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
  48. .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
  49. .attr({title:'Scroll Back to Top'})
  50. .click(function(){mainobj.scrollup(); return false})
  51. .appendTo('body')
  52. if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
  53. mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
  54. mainobj.togglecontrol()
  55. $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
  56. mainobj.scrollup()
  57. return false
  58. })
  59. $(window).bind('scroll resize', function(e){
  60. mainobj.togglecontrol()
  61. })
  62. })
  63. }
  64. }
  65. scrolltotop.init()
  66. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement