简体   繁体   中英

ScrollTo working in nav but need it for all hrefs

I have scrollTo nested inside the template I'm working from. I can't seem to get it to point to my other anchor links (works fine from the nav bar and scroll to top).

My inclination is to do this to make it universal across the site:

  $(window).scroll(function() {
if ($(this).scrollTo() > 100) {
  $('.header').fadeIn('slow');
} else {
  $('.element2').fadeOut('slow');
}

});

$('.body, a').click(function(){
$('html, body').animate({scrollTo : 0},1200);
return false;
});

If I understand you well. You want to animate your page whenever you click any element that is NOT nav.

You could do this.

$(document).click(function(event){
var targetElem = $(event.target);
if(!targetElem.is("nav")){
    $('html, body').animate({scrollTo : 0},1200);
    return false;
 }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM