Z
Z
zayko2011-12-19 19:11:45
JavaScript
zayko, 2011-12-19 19:11:45

jquery, animate not applied for hidden slider?

There is a simple script that organizes the slider. Looks something like this

function slider_init(name){<br>
  var animate_period = 300;<br>
  var id = '#' + name + ' ';<br>
  var slider_element_width = $(id + 'ul li:first').outerWidth(true);<br>
  $(id + '.prev').click(function(e){<br>
    e.preventDefault();<br>
    $(id + 'li:last-child').prependTo(id + 'ul');<br>
    $(id + 'ul').css('left', -slider_element_width + 'px');<br>
    $(id + 'ul').animate({ 'left': '0px' } , animate_period);<br>
  });<br>
  $(id + '.next').click(function(e){<br>
    e.preventDefault();<br>
    $(id + 'li:first-child').appendTo(id + 'ul');<br>
    $(id + 'ul').css('left', '0px');<br>
    $(id + 'ul').animate({ 'left': -slider_element_width + 'px'} , animate_period);<br>
  });<br>
}<br>


rearranges the elements of the list - from the end to the beginning or from the beginning to the end and scrolls the left css property.

There are 2 identical sliders on the page (2 types of page display). One is hidden by default. When you press the button - the blocks are shown / hidden - and then we can see the 2nd slider.

The fact is that the animation of the first slider is working fine. The second slider has no animation - it just instantly clicks through the blocks.

The sliders are identical - the only difference is in the id.

There is an assumption that this is due to the fact that the parent block in which the slider is located is not displayed when the page loads.

I tried to reinitialize the slider - by calling the function when the button for displaying the second version of the page is pressed, but then the slider generally behaves comatosely and frantically podglyuchivaet during the animation.

What to do? What could be the reason?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2011-12-19
Protko @Fesor

requestAnimationFrame - 5 minutes remembering this thing ...

V
Vitaly Zheltyakov, 2011-12-19
@VitaZheltyakov

An error in calculating coordinates is possible - you need to look at the entire code.
What kind of blocks do you have (with fixed not fixed width), what container of blocks?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question