jquery - Figuring out total height of a div -



jquery - Figuring out total height of a div -

i want create simple vertical slider on website. simple code

$('.down').click(function(){ $('#container_slider_youtube').animate({ margintop: '-=410px'}, 1000); }); $('.up').click(function(){ $('#container_slider_youtube').animate({ margintop: '+=410px'}, 1000); });

i can slide container in , downwards works fine. problem i'm having can maintain pressing or downwards button totally messes position of div. what's way prepare problem?

might improve not rely on relative values, , instead, compute new, static values assign .animate().

also, applications such this, find it's way more simpler utilize css position , top instead of relying on margin. (older) browsers seem have hate negative margins fire fire of one thousand hells.

// illustration var container = $('#container_slider_youtube'), parent = container.parent(), step = 410 ; $('.down').click(function () { var currenttop = container.css('top'), newtop = math.max(0, currenttop - step) ; container.animate({ margintop : newtop }, 1000); });

you can adapt .up click. create sure business relationship height of container parent (using .height() probably).

if you're going go css position route, create sure container parent at least position:relative, , container at least same well. set container position:absolute.

jquery slider

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

r - url in CRAN extension manual -

asp.net - .NET Control.ID property inconsistency -