FreeTextHost.in host your text & codes anonymously


FREE TEXT HOST

You can save codes, scripts, sources & general debugging text and share / access / use them at any time (anonymously).
You can even set yourself a password if you want to keep it just for yourself.

Posted by "scroll to top" on Sat, August 18th, 2012, 11:42 AM - Never Expires
Download | New paste

  1. var scrolltotop={
  2. //startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
  3. //scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
  4. setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
  5. controlHTML: '<img src="http://photoserver.ws/images/SZ4Y4fe652e23813e.png" style="filter:alpha(opacity=80); -moz-opacity:0.8; width:70px; height:80px" />', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
  6. controlattrs: {offsetx:10, offsety:20}, //offset of control relative to right/ bottom of window corner
  7. anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
  8.  
  9. state: {isvisible:false, shouldvisible:false},
  10.  
  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.  
  22. keepfixed:function(){
  23. var $window=jQuery(window)
  24. var controlx=$window.scrollLeft() + $window.width() - this.$control.width() - this.controlattrs.offsetx
  25. var controly=$window.scrollTop() + $window.height() - this.$control.height() - this.controlattrs.offsety
  26. this.$control.css({left:controlx+'px', top:controly+'px'})
  27. },
  28.  
  29. togglecontrol:function(){
  30. var scrolltop=jQuery(window).scrollTop()
  31. if (!this.cssfixedsupport)
  32. this.keepfixed()
  33. this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
  34. if (this.state.shouldvisible && !this.state.isvisible){
  35. this.$control.stop().animate({opacity:1}, this.setting.fadeduration[0])
  36. this.state.isvisible=true
  37. }
  38. else if (this.state.shouldvisible==false && this.state.isvisible){
  39. this.$control.stop().animate({opacity:0}, this.setting.fadeduration[1])
  40. this.state.isvisible=false
  41. }
  42. },
  43.  
  44. init:function(){
  45. jQuery(document).ready(function($){
  46. var mainobj=scrolltotop
  47. var iebrws=document.all
  48. mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
  49. mainobj.$body=(window.opera)? (document.compatMode=="CSS1Compat"? $('html') : $('body')) : $('html,body')
  50. mainobj.$control=$('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
  51. .css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
  52. .attr({title:'TheSwagStuff Go to TOP'})
  53. .click(function(){mainobj.scrollup(); return false})
  54. .appendTo('body')
  55. if (document.all && !window.XMLHttpRequest && mainobj.$control.text()!='') //loose check for IE6 and below, plus whether control contains any text
  56. mainobj.$control.css({width:mainobj.$control.width()}) //IE6- seems to require an explicit width on a DIV containing text
  57. mainobj.togglecontrol()
  58. $('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
  59. mainobj.scrollup()
  60. return false
  61. })
  62. $(window).bind('scroll resize', function(e){
  63. mainobj.togglecontrol()
  64. })
  65. })
  66. }
  67. }
  68.  
  69. scrolltotop.init()
Language:
To highlight particular lines, prefix each line with @@








freetexthost.in © 2010-2013 - Powered by PASTE 1.0   website by GandhiG.com