...

View Full Version : jquery: the bug i made through window.size



lauthiamkok
08-08-2009, 01:20 PM
hi,
I posted a couple of threads how to get window size and thanks for all replies and helps,
http://www.codingforums.com/showthread.php?p=849100#post849100

this is the final code i made,

$(document).ready(function(){
$('#slide_2').show();
cssmenu();
animatesize();

$(window).resize(function(){
$('#container').animate({marginLeft:'0px'});
animatesize();
});

});

this.cssmenu = function(){
$("#homemenu > ul > li ").hover(function(event){
$(this).find('a').css({color:'#913291'});
},function(){
$(this).find('a').css({color:'#333333'});
});
}

this.animatesize = function(){
var height_window = $(window).height();
var width_window = $(window).width();

var margin_left = (width_window/2) - (840/2);
$('.slide').css({width:width_window+'px'});
$('.content').css({marginLeft:margin_left+'px'});
$('#enter').click(function () {
alert(width_window);
$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
return false;
});

$('#back').click(function () {
$('#container').animate({marginLeft:'0px'}, 600);
return false;
});
}

there is a bug though which i cannot understand and fix at all.

if u click on the 'enter' button without resizing the window. the alert which i put in for testing, only occurs once. (this is what i expect)

but if u resize the window, then the alert occurs twice and more depends on how many times u resize the window! (this is not what i expect)

http://lauthiamkok.net/tmp/jquery/window.size/

many thanks if u know why and let me know how to fix it.

cheers,
Lau



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum