Created
August 2, 2012 22:19
-
-
Save og-shawn-crigger/3241271 to your computer and use it in GitHub Desktop.
UItoTop jQuery Plugin 1.2 by Matt Varone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|-------------------------------------------------------------------------- | |
| UItoTop jQuery Plugin 1.2 by Matt Varone | |
| http://www.mattvarone.com/web-design/uitotop-jquery-plugin/ | |
|-------------------------------------------------------------------------- | |
*/ | |
(function(a){a.fn.UItoTop=function(d){var f={text:"To Top",min:200,inDelay:600,outDelay:400,containerID:"toTop",containerHoverID:"toTopHover",scrollSpeed:1200,easingType:"linear"},e=a.extend(f,d),c="#"+e.containerID,b="#"+e.containerHoverID;a("body").append('<a href="#" id="'+e.containerID+'">'+e.text+"</a>");a(c).hide().on("click.UItoTop",function(){a("html, body").animate({scrollTop:0},e.scrollSpeed,e.easingType);a("#"+e.containerHoverID,this).stop().animate({opacity:0},e.inDelay,e.easingType);return false}).prepend('<span id="'+e.containerHoverID+'"></span>').hover(function(){a(b,this).stop().animate({opacity:1},600,"linear")},function(){a(b,this).stop().animate({opacity:0},700,"linear")});a(window).scroll(function(){var g=a(window).scrollTop();if(typeof document.body.style.maxHeight==="undefined"){a(c).css({position:"absolute",top:g+a(window).height()-50})}if(g>e.min){a(c).fadeIn(e.inDelay)}else{a(c).fadeOut(e.Outdelay)}})}})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
jQuery.noConflict(); | |
jQuery.noConflict()(function(){ | |
jQuery.UItoTop({ easingType: 'easeOutQuart' }); | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|-------------------------------------------------------------------------- | |
| UItoTop jQuery Plugin 1.2 | |
| http://www.mattvarone.com/web-design/uitotop-jquery-plugin/ | |
|-------------------------------------------------------------------------- | |
*/ | |
#toTop { | |
display:none; | |
text-decoration:none; | |
position:fixed; | |
bottom:10px; | |
right:10px; | |
overflow:hidden; | |
width:51px; | |
height:51px; | |
border:none; | |
text-indent:100%; | |
background:url(../img/ui.totop.png) no-repeat left top; | |
} | |
#toTopHover { | |
background:url(../img/ui.totop.png) no-repeat left -51px; | |
width:51px; | |
height:51px; | |
display:block; | |
overflow:hidden; | |
float:left; | |
opacity: 0; | |
-moz-opacity: 0; | |
filter:alpha(opacity=0); | |
} | |
#toTop:active, #toTop:focus { | |
outline:none; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
|-------------------------------------------------------------------------- | |
| UItoTop jQuery Plugin 1.2 by Matt Varone | |
| http://www.mattvarone.com/web-design/uitotop-jquery-plugin/ | |
|-------------------------------------------------------------------------- | |
*/ | |
(function($){ | |
$.fn.UItoTop = function(options) { | |
var defaults = { | |
text: 'To Top', | |
min: 200, | |
inDelay:600, | |
outDelay:400, | |
containerID: 'toTop', | |
containerHoverID: 'toTopHover', | |
scrollSpeed: 1200, | |
easingType: 'linear' | |
}, | |
settings = $.extend(defaults, options), | |
containerIDhash = '#' + settings.containerID, | |
containerHoverIDHash = '#'+settings.containerHoverID; | |
$('body').append('<a href="#" id="'+settings.containerID+'">'+settings.text+'</a>'); | |
$(containerIDhash).hide().on('click.UItoTop',function(){ | |
$('html, body').animate({scrollTop:0}, settings.scrollSpeed, settings.easingType); | |
$('#'+settings.containerHoverID, this).stop().animate({'opacity': 0 }, settings.inDelay, settings.easingType); | |
return false; | |
}) | |
.prepend('<span id="'+settings.containerHoverID+'"></span>') | |
.hover(function() { | |
$(containerHoverIDHash, this).stop().animate({ | |
'opacity': 1 | |
}, 600, 'linear'); | |
}, function() { | |
$(containerHoverIDHash, this).stop().animate({ | |
'opacity': 0 | |
}, 700, 'linear'); | |
}); | |
$(window).scroll(function() { | |
var sd = $(window).scrollTop(); | |
if(typeof document.body.style.maxHeight === "undefined") { | |
$(containerIDhash).css({ | |
'position': 'absolute', | |
'top': sd + $(window).height() - 50 | |
}); | |
} | |
if ( sd > settings.min ) | |
$(containerIDhash).fadeIn(settings.inDelay); | |
else | |
$(containerIDhash).fadeOut(settings.Outdelay); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be nice if the developer could get it to work with jQuery v1.10