scroll - Trouble with jquery scrollTop function -


i'm trying follow dry principle changing bunch of repeated functions, i'm stuck here. want change scroll function repeated 4 times different classes , ids more generic way (i'm using jquery):

  $('.empresa').click(function(event){     $('html, body').animate({         scrolltop: $("#empresa").offset().top     }, 500);     return false;   });   $('.nosotros').click(function(event){     $('html, body').animate({         scrolltop: $("#nosotros").offset().top     }, 500);     return false;   }); 

the classes elements of navigation within ul looks this.

<ul class="nav">     <li><a href="index#nosotros" class="nosotros">link anchor</a></li>     <li><a href="index#empresa" class="empresa">link anchor</a></li> </ul> 

and scroll tags div elements tags.

<div class="some-random-class" id="empresa" name="empresa"> <div class="some-random-class" id="nosotros" name="nosotros"> 

i using new selector grab class of list proper anchor i'm having trouble scroll part of function, don't know use/convert class or name of object extracted id can keep use same way doing before.

$('.nav li').children('a').click(function() {     alert( $(this).attr('class') ); }); 

hope guys can me!

$('.nav > li > a').click(function(e){     e.preventdefault();     $('html,body').animate({        scrolltop: $('#'+$(this).prop('class')).offset().top     }); }); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -