0

I'm having a problem with css positions !! i want the position of an image to be fixed when the user scrolls till some point and the position should be set to relative after that .

Thanks in advance !

3
Contributors
15
Replies
16
Views
6 Years
Discussion Span
Last Post by Taywin
0

That is not easy to do because you will have to monitor the scrolling position. How about breaking the display into 2 divs, and then put the "fixed" part inside one of the div. The moving should stop once you scroll pass the div that the fixed part is in.

0

That is not easy to do because you will have to monitor the scrolling position. How about breaking the display into 2 divs, and then put the "fixed" part inside one of the div. The moving should stop once you scroll pass the div that the fixed part is in.

Thanks for the reply but i didnt understand it! we'll place 2 divisions and one of it is fixed , but how ll it disappear after the scroll gets over at some point!

0

Do you mean hide the fixed part and show the part in the relative area? By the way, what browser are you using to do the "fixed" position? I know that IE has different implementation.

Edited by Taywin: n/a

0

you could indeed create 2 divs, and when your mouse goes over the second div, you could use JavaScript to change the position.
I know it's not the same as scrolling, but quite frankly, i don't even know if that is possible.

0

@phoenix_2000
That's actually a clever idea. :) Yes, you could do it using onmouseover event on each div. You could have 2 of the same image display in both div but one is set to fixed and the other is relative. Though, if the mouse cursor is on one, then hide the other if it is not hide. :)

0

Ya , but now i have used some logic and i have got the image to move down 2px / scroll but now im having another problem !! is there any event like "ONSCROLLUP" and "onscrolldown", and when i use object.offsettop it gets me the top of the object relatively to the document , but i want the top position of the element with respect tot he screen , is that possible ?

0

If you use offsetTop or offsetLeft, you need to iterate up to the parent element you want to sum the total value (in this case, it could be body tag). If you use it only once, the value is the current relate to its directly parent element. ;)

0

@taywin so are u suggesting me to loop it with a condition ??? :)

@pheonix , that article was good thanks mate :)

0

And guys another thing i want to know !! is it possible to find out which element is on the screen !?

0

Guys i still haven't got it to work !!! :( let me give an example of i want it to be like !! in the new Facebook interface on the right side there's a new feature where we can see all the status updates and stuff from friends !! when we scroll down till some distance its position is relative !! after some distance its position becomes fixed and vice-verse!! that's what i'm looking for !

0

Hmm... Could I see your draft script and the display in HTML? Don't need detail... You could do something like...

// script part
function callThisFunc(arg1, arg2, ...) {
  ...
  ...
  var realOffsetT = 0
  while(node!=targetParent) {
    realOffsetT += node.offsetTop
    node = node.parentNode
  }
  ...
}

// HTML part
...
...
<div class="fixedDisplay">
  ...
</div>
...
...
<div class="relativeDisplay">
  ...
  ...
</div>
...
0

lets say

<table>
<tr>
<td id="td1">
place where some content is located !
</td>
<td id="td2">
place where a small image is located at the top of the "td" and position is fixed
</td>
</tr>
</table>
now what i want the script to do is , once the user starts scrolling , once image in td2 reaches the point where "td1" leaves the screen (bottom of td1 leaves the screen upwards and goes off the screen) the position of the image in "td2" should not be fixed , !!

0

Hmm... You know... The more you explain, the more I am confuse about the word "fixed"? The reason is that before I thought the "fixed" means you use CSS to do the "position: fixed" which does not work really well in IE, but now I am not sure. Is it like...

/*
The current screen...
+-----------------+-------+  <-- 0px
|  content        |  img  |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
+-----------------+-------+  <-- 600px


now scroll down to 600px, where is the image?
+-----------------+-------+  <-- 600px
|  content        |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
|                 |       |
+-----------------+-------+  <-- 1200px
*/

Maybe what you need is position:absolute???

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.