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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -