Discussion:
Scrolling Problem
macgyver47
2010-02-20 15:13:53 UTC
Permalink
Hi
I have
div1 class="post"
div class="title"

div2 class="post"
div class="title"

div3 id="post"
div class="title"
....

div10 id="post"
div class="title"
I am trying: clicking on div#title belonging to div1 scrolls to
div#title belonging to div2 and so on
to cut a long story short clicking on div#title scrolls to the next
div#title and so on
I have tried and not succeded so far
Any help will be very much appreciated
jean
Nathan Klatt
2010-02-20 20:34:26 UTC
Permalink
Post by macgyver47
div1 class="post"
   div class="title"
....
div10 id="post"
  div class="title"
I am trying: clicking on div#title belonging to div1 scrolls to
div#title belonging to div2 and so on
$().ready(function() {
$(".title").click(function() {
var thisPost = $(this).parent();
var nextPost = thisPost.next(".post");
if ( ! nextPost.length ) nextPost = thisPost.parent().find(".post");
var positionOfNextTitle = nextPost.find(".title").position(); // or offset()
window.scrollTo(positionOfNextTitle.left, positionOfNextTitle.top);
});
});

http://jsbin.com/adoti/edit

Nathan
macgyver47
2010-02-21 06:24:24 UTC
Permalink
Thanks Nathan, it works as expected !
Great help !
Post by Nathan Klatt
Post by macgyver47
div1 class="post"
   div class="title"
....
div10 id="post"
  div class="title"
I am trying: clicking on div#title belonging to div1 scrolls to
div#title belonging to div2 and so on
$().ready(function() {
  $(".title").click(function() {
    var thisPost = $(this).parent();
    var nextPost = thisPost.next(".post");
    if ( ! nextPost.length ) nextPost = thisPost.parent().find(".post");
    var positionOfNextTitle = nextPost.find(".title").position(); // or offset()
    window.scrollTo(positionOfNextTitle.left, positionOfNextTitle.top);
  });
});
http://jsbin.com/adoti/edit
Nathan
Loading...