Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts

    jquery: get the window size when minimise it.

    hi,
    this is the code i get the window size (width) when the page is ready.

    Code:
    $(document).ready(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 () {
    		$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
    	return false;
    	});	
    	
    	$('#back').click(function () {
    		$('#container').animate({marginLeft:'0px'}, 600);
    	return false;
    	});
    });

    ideally, i hope to get the window size as well when you make the window smaller by dragging it... what event should i be using then??

    this is the implimentation of the entire code,
    http://partexchangeco.org.uk/home.php

    many thanks,
    Lau

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    You'd want the "resize" event seen here http://docs.jquery.com/Events/resize

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    117
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Iszak View Post
    You'd want the "resize" event seen here http://docs.jquery.com/Events/resize
    got it thanks. i have made the code, but i still have a little problem with resize event - how can i write it in if/ else condition??

    if window resize, run this code,
    Code:
    $(window).resize(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 () {
    		$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
    		return false;
    		});	
    		
    		$('#back').click(function () {
    			$('#container').animate({marginLeft:'0px'}, 600);
    		return false;
    		});
    	});
    else run this,

    Code:
    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 () {
    		$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
    	return false;
    	});
    thanks,
    L


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •