[ 3 posts ]

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile
Tags:

ScrollIntoView doesn't work.

Post Posted: Mon Jun 25, 2012 9:06 pm
+0-
I couldn't get scrollIntoView() to work, so tried a simplied test. The problem is that it doesn't work either.

The code is very simple:

Code:
<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title>Example App</title>
   
    <style>
     .one{
        height: 1300px;
        background: red;
     }
     .two{
        
     }
     </style>
</head>
<body>

    <h1>test</h1>

   <div class="one"><span id="someContent">some content</span></div>
   <div class="two"><a id="link" href="#">Test</a></div>
    <script src="http://yui.yahooapis.com/3.6.0pr3/build/yui/yui-min.js"></script>
    <script>

    YUI().use('gallery-scrollintoview', function (Y) {

       Y.one('#link').on('click', function(e){
          e.preventDefault();

          Y.log('hey');
          Y.log(Y.one('#someContent'));
          Y.one('#someContent').scrollIntoView();
       });

    });
    </script>

</body>
</html>


Clicking the link called "test" at the very bottom of the page should scroll the span called "someContent" into view, but for some reason, it doesn't do that at all.

Is there something I am doing wrong? I have tested with 3.5.1 and 3.6.0pr3, but couldn't get the scrolling to work.

John Lindal

YUI Contributor

  • Username: jafl
  • Joined: Mon Nov 02, 2009 2:33 pm
  • Posts: 351
  • Location: Los Angeles, CA
  • Twitter: jafl5272
  • GitHub: jafl
  • Gists: jafl
  • Offline
  • Profile
Tags:

Re: ScrollIntoView doesn't work.

Post Posted: Tue Jun 26, 2012 4:41 pm
+0-
This example is an edge case because it requires scrolling the body, not some other DOM element. The body element is special, because the viewport height is what matters, not the element's clientHeight. I will upload a patch to the ticket you opened on github.

John Mizliso

  • Username: abxccd
  • Joined: Sun Jan 22, 2012 11:20 pm
  • Posts: 48
  • Offline
  • Profile

Re: ScrollIntoView doesn't work.

Post Posted: Tue Jun 26, 2012 5:34 pm
+0-
Thanks John! :D
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum