Note that there are some explanatory texts on larger screens.

plurals
  1. POSlider with buttons. How to improve?
    primarykey
    data
    text
    <p>I need to make a slider.</p> <p>I have content (which should shift horizontally) and two buttons - "right" and "left". </p> <p>If you press the button and hold it, the content starts to move (in the appropriate direction). If you not hold the button, then the movement stops. This behavior copies the behavior of a usual window scrollbar.</p> <p>I wrote some code:</p> <pre><code>var animateTime = 1, offsetStep = 5; //event handling for buttons "left", "right" $('.bttR, .bttL') .mousedown(function() { scrollContent.data('loop', true).loopingAnimation($(this)); }) .bind("mouseup mouseout", function(){ scrollContent.data('loop', false); }); $.fn.loopingAnimation = function(el){ if(this.data('loop') == true){ var leftOffsetStr; leftOffsetInt = parseInt(this.css('marginLeft').slice(0, -2)); if(el.attr('class') == 'bttR') leftOffsetStr = (leftOffsetInt - offsetStep).toString() + 'px'; else if(el.attr('class') == 'bttL') leftOffsetStr = (leftOffsetInt + offsetStep).toString() + 'px'; this.animate({marginLeft: leftOffsetStr}, animateTime, function(){ $(this).loopingAnimation(el); }) } return this; } </code></pre> <p>But it does have a few things that I do not like:</p> <ol> <li>It always calls the function animation (<code>loopingAnimation</code>) - I think that this is an extra load (not good).</li> <li>When moving content he "twitches and trembling" - (it's not pretty).</li> </ol> <p>How can I solve this problem more <strong>elegantly</strong> and without the drawbacks of my code?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload