jquery - get css value for variable -


i have made basic social slider bar hides @ side of site, slides out on hover. works if give jquery set values current css 'left' property, when try , left property , set variable script stops working. have missed something?

$('#slider').mouseenter(function () {      var cssleft = $(this).css('left');      if ($('#slider').css('left') === "cssleft") {         $(this).animate({             left: '0'         }, 300, function () {});     } else {         $(this).animate({             left: ("cssleft" + 'px')         }, 100, function () {});     }  });  $('#slider').mouseleave(function () {     $(this).delay(1000).animate({         left: ("cssleft" +  'px')     }, 500, function () {}); }); 

there working version set values here

http://jsfiddle.net/tjtnm/

thanks guys!

define , initialize left offset variable outside of jquery actions:

var cssleft = $('#slider').css('left');  $('#slider').mouseenter(function () {     if ($('#slider').css('left') === cssleft) {         $(this).animate({             left: '0'         }, 300, function () {});     } else {         $(this).animate({             left: cssleft         }, 100, function () {});     }  });  $('#slider').mouseleave(function () {     $(this).delay(1000).animate({         left: cssleft     }, 500, function () {}); }); 

also, not put quotes around variable cssleft otherwise interpreted string.

see: http://jsfiddle.net/audetwebdesign/qr7z5/

footnote

the html5 approach using transitions more elegant, shown in post theftprevention


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -