Jump to content

jQuery Resize strange activity


onlyican

Recommended Posts

hi all

 

I am rebuilding a site.

 

Basically I have a page which has 2 boxes on the right hand side which fill the screen

 

On Load one big is hidden

 

On click of a P tag, javascript runs, gets the available height (depending on the height of the window), divides by 2, then shows the 2nd div.

 

Then you click an X image on the 2nd div, and that div hides again, then resizes the first div to full height.

 

Works fine FIRST TIME

 

BUT

 

when I click the P tag the 2nd time (after hiding the div) it goes weird

Close the div, try third time, works perfect

Try fourth time, goes weird again

 

Example link

http://help.rideandtag.co.uk/main.php

 

Theres no PHP coding, so all can be seen via source code.

 

TRY it

 

1) Click "Show listing Demo" on the left hand side.

2) Blue box appears

3) Click the X on the top right of the BLUE box

4) Blue box goes

 

5) Click Show Listing Demo on left hand side again

6) WTF!!!!

7) Click the X again in the blue box)

8) Repeat from 1 and get same results

 

 

EDIT:// Console.log has some debug, shows the height being set to 0. Dont know why the maths does not equal 0

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/264345-jquery-resize-strange-activity/
Share on other sites

try something like this

 

var isBoxShowen = false;
function showMap(){
    if(!isBoxShowen){
        showBox();
        isBoxShowen = true;
    }
}
function hideMap(){
    isBoxShowen = false;
}

 

ps: i recommend using http://api.jquery.com/visible-selector/

Fixed it.

 

For some reason when I set the desc box to visible it was causing a scroll , thus pushing main down to float under sidebar, thus causing offset to be the height of the document.

Resulting is height of document minus offset of map (being below doc height) total 0. but by the time the debug spat the code out, it was back to the top, thus showing incorrect figures in the console log (and not showing a scroll bar)

 

Simple fix, set the width to 0 (so the scroll wont force the position below the page) at the start of the function and reset the width at the end

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.