Created
November 14, 2013 11:48
-
-
Save jervert/7465527 to your computer and use it in GitHub Desktop.
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
/* | |
* SliceAnchor - jQuery plugin for fake anchors | |
* | |
* Copyright (c) 2012 Antonio Rodríguez Ruiz | |
* | |
* Licensed under the MIT license: | |
* http://www.opensource.org/licenses/mit-license.php | |
* | |
* Project home: | |
* http://outbook.es | |
* | |
* Version: 1.0.0 | |
* | |
* params: | |
* options { | |
* attrSelector: [String with anchor selector attribute] | |
* animateTime: [Integer with animation time in miliseconds] | |
* } | |
* | |
* html: | |
* <span role="link" tabindex="0" data-navigate-anchor="#destination-selector">[...]</span> | |
* | |
* initialize: | |
* $('.fake-link-selector').sliceAnchor({attrSelector: 'data-navigate-anchor', animateTime: 1000}) | |
* | |
*/ | |
$.fn.extend({ | |
sliceAnchor: function (data) { | |
var defaults = { | |
attrSelector: 'data-navigate-anchor', | |
animationTime: 50 | |
}, | |
options = $.extend(true, defaults, data), | |
navigateAnchor = function (event) { | |
var destinationSelector = $(event.currentTarget).attr(options.attrSelector), | |
$destination = $(destinationSelector); | |
$('html, body').animate({ | |
scrollTop: $destination.offset().top | |
}, options.animationTime, function () { | |
$destination.focus(); | |
}); | |
}; | |
return this.each(function () { | |
$(this).on('click.navigateAnchor', navigateAnchor); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment