views:

39

answers:

2

An Example of the problem

Randomly i have a character on screen. He starts offscreen and smoothly moves onto the screen. However i have the problem with it moving offscreen. Right now i put him in the body using jquery. When it gets to the right side i plan to remove him by checking the width and waiting until he is completely out of screen (just before he is out of screen half his body should be painted). The problem is when he moves to the right the width gets larger and i see a scrollbar appear.

How do i make a character not affect the width, have its body partially painted (on the right side, left side is not an issue) and know when it is completely out of sight?

+1  A: 

Just set overflow:hidden; on your html element:

html {
   overflow:hidden;
}

jsfiddle example

Lee
I dont *know* if i'll need a scrollbar so this is only half right. It wont work well if the page is naturally must scroll http://jsfiddle.net/44nwt/6/ so i'll figure it out in the next few days +1
acidzombie24
you can get around this by wrapping the rest of your page in a div with `overflow:auto; min-height:100%;`. You also need `margin:0;padding:0;height:100%;` on *both* `html` and `body`. [http://jsfiddle.net/44nwt/7/](http://jsfiddle.net/44nwt/7/)
Lee
+2  A: 
function MoveCode(){
    var l = $('.ball').css("left");
    $('.ball').css("left", (parseInt(l) + 8) + "px");
    setTimeout(MoveCode, 160);
}

$('body').append('<div style="width:100%; overflow:hidden;"><img class="ball" src="http://michaelreid.typepad.com/.a/6a00e54edabd838833011168a00f09970c-800wi"/&gt;&lt;/div&gt;');
MoveCode()

just wrap your image in a div so you have something to set the overflow:hidden on without screwing with the page.

nathan gonzalez
+1 - this approach will work too (and it's probably better than the one I suggested above). But you'll need the wrapper div to be `position:absolute;` otherwise, it won't work. [http://jsfiddle.net/44nwt/8/](http://jsfiddle.net/44nwt/8/).
Lee
@Lee, @nathan gonzalez: Thank you both
acidzombie24