Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var resume = false;

$(document).ready(function(){
swing();
$('#share').bind({
hover: function () {
$(this).stop();
},
mouseleave: function () {
var v = parseInt($("#share").css('right'), 0);

if (resume)
swing(v);
else
swingBack();
}
});
});


function swing(v){
var total = 1500;
var disremain = v ?1500-Math.abs(v):1500;

$('#share').animate({
right: '+=' + disremain + 'px'
}, 8000*(disremain)/total, function(){
resume = false;
swingBack();

});
}

function swingBack(v) {
var total = 1500;
var disremain = v ? 1500 - Math.abs(v) : 1500;
$('#share').animate({
right: '0px'
}, 8000 * (disremain) / total, function () {
resume = true
swing();
});
}
Posted
Updated 30-Jul-12 20:52pm
v3
Comments
bbirajdar 30-Jul-12 8:11am    
"nothing happens,it is still stopping." in not a technical explanation of a problem..
Sergey Alexandrovich Kryukov 30-Jul-12 12:53pm    
Nevertheless, I provided an answer, as this code does not look right; please see.
--SA

I cannot see proper structure of the code; in particular, setting the event handlers. Besides, you can setup two handlers by the .hover method — both "mouse in" and "mouse out":
C#
$(document).ready(function () {
    //...
    hoverElement = $(#share);
    $(hoverElement).hover(
        function () {
            // mouse in handler
        }, 
        function () {
            // mouse out handler
        }
    );  
});


Please see:
http://api.jquery.com/hover/[^].

Can you see the difference? The .hover handlers are added in the handler of document.ready, which provides right order of execution.

Besides, you can use a JavaScript debugger to check up two things: 1) if the handler is added, 2) if the handler is triggered.

—SA
 
Share this answer
 
v4
Comments
firstfox 31-Jul-12 2:56am    
i corrected the code.and now functions are called and everything is working fine.but the problem is that my animation extremly slows down after resuming so i multiplied time by remaing distance/total distance and this is working fine for the SWING function but on SWING BACK it still slows down after resuming.
Sergey Alexandrovich Kryukov 31-Jul-12 11:26am    
Well, performance is not a simple issue, especially in interpreted code. Perhaps you need to profile execution to reveal some bottlenecks.
--SA
C#
#share{
 position:absolute;

}
C#
var resume = false;

$(document).ready(function(){
    swing();
    $('#share').bind({
        hover: function () {
            $(this).stop();
        },
        mouseleave: function () {
           // var v = parseInt($("#share").css('right'));

            if (resume){
                var v = parseInt($("#share").css('right'));
                document.getElementById('<%=Label1.ClientID%>').innerHTML = "right of image    " + v;
                swing(v);}
            else {
                var v = parseInt($("#share").position().left) - 300;
                document.getElementById('<%=Label2.ClientID%>').innerHTML = "left of image    " + v;
                swingBack(v);}
        }
    });
});



function swing(v){
    var total = 800;
    var disremain = v ? 800 - Math.abs(v) : 800;
    document.getElementById('<%=Label3.ClientID%>').innerHTML = "disremainin go  "+disremain;
  $('#share').animate({
      right: '+=' + disremain + 'px'
  }, 4000*(disremain)/total, function(){
      resume = false;
      swingBack();

  });
}

function swingBack(v) {
    var total = 800;
    var disremain = v ? 800 - Math.abs(v) : 800;
    document.getElementById('<%=Label4.ClientID%>').innerHTML = "disremainin back    " + disremain;
    $('#share').animate({
        right: '0px'
    }, 4000 * (disremain) / total, function () {
    resume = true;
        swing();
    });
}


so i ended up using the above code,which works as i want in IE,firefox and also chrome.
hope this helps,if anyone needs it. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900