javascript - How to adjust div location on animate -


in webapplication i'm working on, when click on listitem, div pops out. can find example here.

how can adjust top of div listitem?

the div (#home in example) has pop out top next list item.

$(function () {  $("#home_link").click(function () {      $("#home").animate({width: 'toggle'}, 500);  }); }); $(function () { $("#edit_link").click(function () {     $("#home").animate({width: 'toggle'}, 500); }); }); 

so, cleaned of , reorganized it. basically, marked container element (which holds both navs , content), , use determine desired offset. made more generic can add more hyperlinks need! helpful, let me know if have questions why did things way, or how works.

jsfiddle

$(function () {     $("#list a").click(function () {         var $this = $(this);         var $container = $this.closest('[data-id="container"]');         var $target = $($this.attr('href'));          $target.css('margin-top', $this.offset().top - $container.offset().top);         $target.animate({width: 'toggle'}, 500);     }); }); 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -