开发者

javascript/jQuery location.href misses mark

开发者 https://www.devze.com 2023-02-07 08:50 出处:网络
I have a page that has a number of elements that are slid up on startup. I want to be able to slide down a particular pane based on the hash in the url my code is

I have a page that has a number of elements that are slid up on startup. I want to be able to slide down a particular pane based on the hash in the url my code is

    if (window.location.hash.length>0){

开发者_运维知识库   var id = window.location.hash;

   if (id.length==7){ //expected hash is 7 chars long (inc #)

    console.log('Comment hash in url, finding link');

    $(id).parents('.details_wrapper').parent().show().find('.details_wrapper').addClass('open').slideDown('slow', function(){ //unhide and slidedown pane
     window.location.href = id;
    });
   }
  }

Which sort of works in that the appropriate pane is revealed and slid down, however the window.location.href doesn't seem to be working very well as the window consistently places the page about 800px further down than where the anchor is.

As a possible side note it seems I can't verify the correct href as typing

window.location.href='#c83225';

into the developer console (Safari) gives an error. It works in the Chrome console though.


Another option to do that is

window.location.hash = 'c83225';
0

精彩评论

暂无评论...
验证码 换一张
取 消