From 234c80c93dae19f988076118ec13d6ff4cd62101 Mon Sep 17 00:00:00 2001 From: Will Schmierer Date: Fri, 24 Apr 2015 16:41:40 -0400 Subject: [PATCH] prevent screen jump/blinking occurring in some browsers on click link --- Gruntfile.js | 17 ++++++++--------- assets/js/hash-link-scroll-offset.js | 5 +++-- assets/js/hash-link-scroll-offset.min.js | 4 ++-- assets/js/src/hash-link-scroll-offset.js | 3 ++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 5b5a205..1a3c515 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -64,7 +64,7 @@ module.exports = function( grunt ) { test: { files: ['assets/js/test/**/*.js'] }, - + cssmin: { options: { banner: '/*! <%= pkg.title %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' + @@ -75,16 +75,16 @@ module.exports = function( grunt ) { }, minify: { expand: true, - + cwd: 'assets/css/src/', src: ['hash-link-scroll-offset.css'], - + dest: 'assets/css/', ext: '.min.css' } }, watch: { - + styles: { files: ['assets/css/src/*.css'], tasks: ['cssmin'], @@ -92,7 +92,7 @@ module.exports = function( grunt ) { debounceDelay: 500 } }, - + scripts: { files: ['assets/js/src/**/*.js', 'assets/js/vendor/**/*.js'], tasks: ['jshint', 'concat', 'uglify'], @@ -108,13 +108,12 @@ module.exports = function( grunt ) { grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-cssmin'); - + grunt.loadNpmTasks('grunt-contrib-watch'); // Default task. - + grunt.registerTask( 'default', ['jshint', 'concat', 'uglify', 'cssmin'] ); - grunt.util.linefeed = '\n'; -}; +}; \ No newline at end of file diff --git a/assets/js/hash-link-scroll-offset.js b/assets/js/hash-link-scroll-offset.js index b769a86..9a6307d 100644 --- a/assets/js/hash-link-scroll-offset.js +++ b/assets/js/hash-link-scroll-offset.js @@ -1,4 +1,4 @@ -/*! Hash Link Scroll Offset - v0.1.0 - 2015-04-23 +/*! Hash Link Scroll Offset - v0.1.0 - 2015-04-24 * http://webdevstudios.com * Copyright (c) 2015; * Licensed GPLv2+ */ /*jslint browser: true */ @@ -14,7 +14,8 @@ window.Hash_Link_Scroll_Offset = (function(window, document, $, undefined){ app.offset = app.getOffset(); // Handle clicking hash links - $( 'a[href^="#"]:not(.no-scroll)' ).on( 'click', function() { + $( 'a[href^="#"]:not(.no-scroll)' ).on( 'click', function(event) { + event.preventDefault(); app.scrollToHash( this.hash ); }); diff --git a/assets/js/hash-link-scroll-offset.min.js b/assets/js/hash-link-scroll-offset.min.js index bb1032e..7d4adc9 100644 --- a/assets/js/hash-link-scroll-offset.min.js +++ b/assets/js/hash-link-scroll-offset.min.js @@ -1,4 +1,4 @@ -/*! Hash Link Scroll Offset - v0.1.0 - 2015-04-23 +/*! Hash Link Scroll Offset - v0.1.0 - 2015-04-24 * http://webdevstudios.com * Copyright (c) 2015; * Licensed GPLv2+ */ -window.Hash_Link_Scroll_Offset=function(o,t,n){"use strict";var s={};return s.init=function(){s.offset=s.getOffset(),n('a[href^="#"]:not(.no-scroll)').on("click",function(){s.scrollToHash(this.hash)}),setTimeout(function(){o.location.hash&&(o.scrollTo(0,0),s.scrollToHash(o.location.hash))},10)},s.getOffset=function(){var t=o.hlso_offset||0;return n("#wpadminbar").length&&(t=""+(parseInt(t,10)+32)),t},s.scrollToHash=function(o){var t=n(o);t.length||(t=n('[name="'+o.substr(1)+'"]')),t.length&&n("html, body").stop().animate({scrollTop:t.offset().top-s.offset},900)},n(t).ready(s.init),s}(window,document,jQuery); \ No newline at end of file +window.Hash_Link_Scroll_Offset=function(t,o,n){"use strict";var s={};return s.init=function(){s.offset=s.getOffset(),n('a[href^="#"]:not(.no-scroll)').on("click",function(t){t.preventDefault(),s.scrollToHash(this.hash)}),setTimeout(function(){t.location.hash&&(t.scrollTo(0,0),s.scrollToHash(t.location.hash))},10)},s.getOffset=function(){var o=t.hlso_offset||0;return n("#wpadminbar").length&&(o=""+(parseInt(o,10)+32)),o},s.scrollToHash=function(t){var o=n(t);o.length||(o=n('[name="'+t.substr(1)+'"]')),o.length&&n("html, body").stop().animate({scrollTop:o.offset().top-s.offset},900)},n(o).ready(s.init),s}(window,document,jQuery); \ No newline at end of file diff --git a/assets/js/src/hash-link-scroll-offset.js b/assets/js/src/hash-link-scroll-offset.js index ed610da..84df545 100644 --- a/assets/js/src/hash-link-scroll-offset.js +++ b/assets/js/src/hash-link-scroll-offset.js @@ -19,7 +19,8 @@ window.Hash_Link_Scroll_Offset = (function(window, document, $, undefined){ app.offset = app.getOffset(); // Handle clicking hash links - $( 'a[href^="#"]:not(.no-scroll)' ).on( 'click', function() { + $( 'a[href^="#"]:not(.no-scroll)' ).on( 'click', function(event) { + event.preventDefault(); app.scrollToHash( this.hash ); });