I have written connect and cancel button code to connect and cancel the page using jquery.
when i scroll down and click the connect button the scroll posi开发者_开发知识库tion is changing(going to top again), what i need is, instead the scroll position should remain unchanged when both Connect and Cancel button is clicked
pls, send some code to solve this problem
We really do need some more details to offer good advice. In particular, how your Connect and Cancel buttons are implemented. What elements they use etc. But I'll try and answer anyway.
If your page is jumping to the top, then one of two things is likely happening.
Either you're submitting a form, and the page is being reloaded. When a new page loads (even if it's the same page), it's initially scrolled to the start.
Or you're following a link to a named element. If your Cancel/Connect button is an anchor that looks like this:
<a href="#">Connect</a>
Then that is likely the case.
If you see a # at the end of your URL after the page scrolls to the top, then the second option is what's happening. In this case, it's a case of either calling the preventDefault method on the event object, or returning false from the event handler.
For example:
<a id="connect-button" href="#">Connect</a>
<script type="text/javascript">
$(function() {
$('#connect-button').click(connect_handler);
});
function connect_handler(e) {
e.preventDefault();
// normal connection code
}
</script>
If this doesn't apply to your situation, then please provide more information, and I'll try and provide a more suitable answer.
精彩评论