javascript - Anchor link to content inside hidden div -


i'm trying link content external page, using

<a name="anchor"></a> 

and

<a href="/somepage/#anchor"></a> 

the content anchor located hidden inside drawer, using jquery:

$(".toggle_container").hide(); 

see fiddle: http://jsfiddle.net/bd1mbu5j/1/

i've tried wrapping head around method found here, know there's i'm missing.

window.onload = function() {     var hash = window.location.hash; // "#div1" or     if(hash != "") {         var id = hash.substr(1); // rid of #         document.getelementbyid(id).style.display = 'block';     } }; 

also should noted, i'm not trying open drawer, link specific content within drawers.

see fiddle http://jsfiddle.net/bd1mbu5j/2/

  $(".toggle_container").hide();   $("h3.trigger").click(function(){     var _this = this;     $(this).toggleclass("active").next().slidetoggle("normal", function () {         var anchor = $(_this).data('anchor');         console.log(anchor);          if (anchor && $('#'+anchor).length) {             console.log($('#'+anchor).offset().top);             $('html, body').animate({scrolltop: $('#'+anchor).offset().top+'px'});         }     });      return false; //prevent browser jump link anchor   }); 

i added target element id data attribute , picked once slide toggle finished. animated down element if exists.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -