javascript - jQuery combine 2 scripts to achieve smooth scrolling to anchor -


i have following jquery function shows / hides content depending on div selected...

jquery(document).ready(function() {   jquery('.showsingle').on('click', function () {     jquery(this).addclass('selected').siblings().removeclass('selected');     jquery('.targetdiv').hide();     var selector = '#div' + jquery(this).data('target');     jquery(selector).show();     location.hash = selector;   }); }); 

http://jsfiddle.net/w4km8/7944/

i have following script taken http://1stwebmagazine.com/jquery-scroll-to-anchor-point

$(document).ready(function(){     $('a[href^="#"]').bind('click.smoothscroll',function (e) {         e.preventdefault();          var target = this.hash,         $target = $(target);          $('html, body').stop().animate({             'scrolltop': $target.offset().top-40         }, 900, 'swing', function () {             window.location.hash = target;         });     }); }); 

i trying combine 2 instead of jumping anchor scrolls it. need combine them or can made work separate?

looks can combine them enough, i've made work jsfiddle: http://jsfiddle.net/9soxbhpj/

var target = jquery(selector); target.show() $('html, body').stop().animate({         'scrolltop': target.offset().top-40     }, 900, 'swing', function () {         window.location.hash = selector;     }); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -