First, I get the window width and minus something then assign it to a variable,
Second, I resize the window and want to get the value that is current window width minus something
but I get wrong value, it will alert two value one is right and another is wrong,I do not know why and how to fix it, help me, thx
my html code is
<p class="test">click me get value</p>
js is
(function(){
test();
$(window).resize(function(){
test();
});
}());
function test() {
var t = $(window).width()-74;
alert('one ' +t);
$(document).on('click', '.test',{t: t}, get);
}
function get(event) {
var l = event.data.t
alert('two ' +l)
}
the fiddle version is http://jsfiddle.net/dxcqcv/xetbhwpv/1/