problem adding/dividing results from css/attr
Im working on a script using scrollTo. When you click an image I want it to center the image on the page, the images are positioned by a parent div.
So far I have the below. It works fine with each of the vars directly placed after the left: but as soon as i try and add/multiply them together it doesnt work. What am I doing wrong? I'm fairly new to jQuery.
Thanks,
<script type="text/javascript">
<!--
$(document).ready(function() {
$('img').click(function(){
var thisleft = $(this).parents("div").css("left");
var thiswidth = $(this).attr("width");
var windowwidth = $(window).width();
var thistarget = thisleft + (windowwidth/2) - (thiswidth/2);
$(document).scrollTo({ top:0, left:thistarget}, 1000);
});
});
//-->
</script>