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.
$(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
Post a Comment