mirror of
https://github.com/e107inc/e107.git
synced 2025-07-31 11:50:30 +02:00
Behavior to enable Smooth Scrolling if URL has a fragment.
This commit is contained in:
@@ -1,5 +1,48 @@
|
|||||||
/* global $ */
|
/* global $ */
|
||||||
|
|
||||||
|
var e107 = e107 || {'settings': {}, 'behaviors': {}};
|
||||||
|
|
||||||
|
(function ($)
|
||||||
|
{
|
||||||
|
// In case the page was opened with a hash, prevent jumping to it.
|
||||||
|
// http://stackoverflow.com/questions/3659072/how-to-disable-anchor-jump-when-loading-a-page
|
||||||
|
if(window.location.hash)
|
||||||
|
{
|
||||||
|
$('html, body').stop().animate({scrollTop: 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Behavior to initialize Smooth Scrolling on document, if URL has a fragment.
|
||||||
|
* TODO: create theme option on the admin panel to:
|
||||||
|
* - enable/disable smooth scrolling
|
||||||
|
* - change animation duration
|
||||||
|
* - set top-offset if theme has a fixed top navigation bar
|
||||||
|
*
|
||||||
|
* @type {{attach: Function}}
|
||||||
|
*/
|
||||||
|
e107.behaviors.initializeSmoothScrolling = {
|
||||||
|
attach: function (context, settings)
|
||||||
|
{
|
||||||
|
if(window.location.hash)
|
||||||
|
{
|
||||||
|
$(context).find('body').once('initialize-smooth-scrolling').each(function ()
|
||||||
|
{
|
||||||
|
if($(window.location.hash).length !== 0)
|
||||||
|
{
|
||||||
|
$('html, body').stop().animate({
|
||||||
|
scrollTop: $(window.location.hash).offset().top
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
})(jQuery);
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function()
|
$(document).ready(function()
|
||||||
{
|
{
|
||||||
$(":input").tooltip();
|
$(":input").tooltip();
|
||||||
|
Reference in New Issue
Block a user