tags:

views:

277

answers:

1

HTML:

<body>
<div class="top-corner"></div> <!-- absolute, top: 0 -->
<div class="bottom-corner"></div> <!--  absolute, bottom: 0 -->
<a href="#" class="top-link">top</a> <!--  fixed, top 50%, left 0 -->
<a href="#" class="bottom-link">bottom</a> <!--  fixed, top 60%, left 0 -->
<div style="padding: 1500px 0;"></div> <!--  for scroll test -->
</body>

Using scrollto plugin http://demos.flesler.com/jquery/scrollTo/

JS

$(".top-link").hover(function(){
    $("body").scrollTo($(".top-corner"), 3000);
},function(){
    // stop on unhover
});
$(".bottom-link").hover(function(){
    $("body").scrollTo($(".bottom-corner"), 3000);
},function(){
    // stop on unhover
});

Animation works on hover. How to stop it on unhover?

Thanks.

+2  A: 

use .stop()

$(".top-link").hover(function(){
    $("body").scrollTo($(".top-corner"), 3000);
},function(){
     $("body").stop();
    // stop on unhover
});
$(".bottom-link").hover(function(){
    $("body").scrollTo($(".bottom-corner"), 3000);
},function(){
    $("body").stop();
    // stop on unhover
});

if the callbacks are just the same, you can also do this,

$(".bottom-link, .top-link").hover(function(){
    var $this = $(this);
    $("body").scrollTo($this, 3000);
},function(){
    $("body").stop();
    // stop on unhover
});
Reigel