Need help with scrollTo
Need help with scrollTo
Hello All,
I'm a newbie to web programming and would really appreciate any help with the scrollTo plugin. The problem I'm facing is I have a bunch of questions and answers for each of these. I lose the scroll position on clicking the answer to any question.
Here's my custom Js Code - Ignore the alert
-
jQuery(document).ready(function(){
jQuery('.answer').hide();
jQuery('.show-answer a').click(function(){
var position = jQuery(this).parent().position();
jQuery(this).parent().hide();
jQuery(this).parent().next().show('slow');
alert(position.top);
jQuery.scrollTo(position.top, {speed:500});
});
});
Here's the Html Code for it. Note that I have truncated the answer_content and question_content
-
<html>
<head>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript' src='scrollTo.js'></script>
<script type='text/javascript' src='custom.js'></script>
</head>
<body>
<div class="entry">
<div class="question">
<p>
QUESTION_CONTENT
</p>
<p>QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT</p>
</div>
<div class="show-answer">
<a href="#" id="click">Answer</a>
</div>
<div class="answer">
<p>Answer 1</p>
</div>
</div>
<div class="entry">
<div class="question">
<p>QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT</p>
</div>
<div class="show-answer">
<a href="#" id="click">Answer</a>
</div>
<div class="answer">
<p>Answer 2</p>
</div>
</div>
<div id="foo" class="entry">
<div class="question">
<p>
QUESTION_CONTENT </p>
<p>
QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT </p>
</div>
<div class="show-answer">
<a href="#" id="click">Answer</a>
</div>
<div class="answer">
<p>Answer 3</p>
</div>
<div class="entry">
<div class="question">
<p>QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT</p>
<p>
QUESTION_CONTENT</p>
</div>
<div class="show-answer">
<a href="#" id="click">Answer</a>
</div>
<div class="answer">
<p>Answer 4</p>
</div>
</div>
</div>
</body>
</html>
Thanks in advance.