1

i´ve found a jquery snippet to set the divs id as .hash to url, now there is following PROBLEM:

When i scroll the page down everything works fine, but when i scroll from bottom to top the page is jumping (because the divs with the # were set top without any transition)

What i want to have is the possibility to scroll the page without jumps but still adding the hash?

$(document).bind('scroll',function(e){
    $('iframe').each(function(){
        if (
            $(this).offset().top < window.pageYOffset + 10

            && $(this).offset().top + $(this).height() > window.pageYOffset + 10
        ) {
            window.location.hash = $(this).attr('id');
        }
    });
});
.hashdiv{
  width: 100vw;
  height: 40vw;
  margin-bottom: 2vh;
  background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>



<iframe id="hashone" class="hashdiv"></iframe>

<iframe id="hashtwo" class="hashdiv"></iframe>

<iframe id="hashthree" class="hashdiv"></iframe>

<iframe id="hashfour" class="hashdiv"></iframe>
D20537
  • 31
  • 1
  • 8
  • http://stackoverflow.com/questions/3503559/prevent-default-hash-behavior-on-page-load – BenG Oct 19 '15 at 21:48
  • I cant find any answer in that link, and maybe i dont understand something. but there they try to do something completely different, or? :) – D20537 Oct 19 '15 at 21:57
  • the marked answer says *There isn't a way to prevent the default hash behaviour* and then explains a work around. – BenG Oct 19 '15 at 22:00
  • Ah, now i get it. But with this "work around" it isn´t possible anymore to copy the url for the user. that was the reason why i´m trying that. but thanks – it´s a bgeinning. – D20537 Oct 19 '15 at 22:53

0 Answers0