4
I need to create a floating div in the left corner of the site. However, it is in the middle of the site and will only follow the scrolling from one point to another. As in the image illustrating, the floating div has to go from the beginning of the content to the end of it, stopping before the "bar".
I tested some codes I found on the internet but none worked right, so I kind of tried to make some adjustments of my own.
I’m using this jQuery code:
var cartaz = SC(".cartaz-flutuante");
SC(window).scroll(function(){
var topo_cartaz = cartaz.offset().top;
var y_fixo = 40;
if (topo_cartaz < 40) {
cartaz.animate({
top: y_fixo+SC(document).scrollTop()+"px"
},{duration:500,queue:false}
);
}
});
The height of '40" is just a margin to give the div, not to stay fully leaned. And that "if" I tried to do for when the page height gets smaller than the margin, the div slip effect starts to work... Only it’s not working... And if I take the if, it works, but then gets high and the floating div goes away if I give a full scroll of the site.
If you align the contents box to the right and put the floating div as position: Fixed, it does not solve?
– Carlos Pereira
The html css structure is very basic, as in the drawing. The floating div is "float left" and the content "float right". The div is already in Absolute, what I can do is leave as "Fixed", dai sim ela acompanha o scroll.. the problem is that it has no effect, and I need to control the movement limit, since it is fixed on the site as a whole, going from header to footer, and not only where I want.
– Ricardo
could put an example in Jsfiddle?
– Caputo
I took the @Freddutra suggestion and tried to create my own code. It can be viewed here: http://jsfiddle.net/rmugb3j0/ but it didn’t work! HAHA I don’t know why. Still, you can get a sense of what my code is like. The floating div slides with the page and stops at the end of the content div, as scheduled. The problem is that when I scroll up, the div does not go back to follow.. How do I do?
– Ricardo