Okay, so I wrote this function yesterday for one of our websites here at the office, the site is responsive, but one of the banners wasn't behaving at a certain screen size (was getting chopped off when screen size was less than 1067px). Basically, this script checks for window size of 1067px (higher than 1068px, banner is fine) to 980px (lower than 981, banner is hidden)
function updateReadyGoBG(){
var vpWidth, difference, position = 0;
vpWidth = jQuery(this).width();
if(vpWidth > 980 && vpWidth < 1067){
position = jQuery(".ready_go_bg").css("left").replace("px", "")
difference = (position - (600 - (vpWidth - position) ) ) + 100;
jQuery(".ready_go_bg").css("left", difference + "px")
}
}
Any ideas on how to improve this to improve performance or reduce calls? Any review, refactoring or just general thoughts would be highly appreciated. What did I do wrong? What would you change?
Thanks all!
EDIT: adding rudimentary html snipped this acts on
<style>
.banner-container{ width:1000px; height:150px; }
.banner{ width: 100% }
.ready_go_bg{ position:absolute; left:600px; top:100px; }
</style>
<div class="banner-container">
<div class="banner">
<span class="ready_go_bg">Ready. Go.</span>
</div>
</div>