Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I have interpret your description correctly, you want a div that moves left and right continuously and changes content on "arrival". I'm still not sure if you want to toggle content or loop through more content.</p> <p>A little illustration to clarify:</p> <pre><code> __________ __________ | | &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; | | | content1 | | content2 | |__________| &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; |__________| |---------------------------------| content change content change </code></pre> <p>Now, because the VERY specific request, I highly doubt there's such a plugin available. You just have to be creative yourself! Luckily, I'm a nice guy and save you some work.</p> <p>See the <a href="http://jsfiddle.net/NUK72/" rel="nofollow">online demo</a>.</p> <p>My javascript function:</p> <pre><code>function startBouncing(selector, content, duration, easing) { // get the required movement (parent width - element width) var movement = $(selector).parent().width() - $(selector).width(); var contentIndex = 0; // we want to start with content index 0 // define function that makes element go forth var goForth = function() { // start animation and change text $(selector).animate({ 'margin-left': movement }, duration, easing, goBack).children('p:first').html(content[contentIndex % content.length]); contentIndex++; // increment index for next time }; // define function that makes element go back var goBack = function() { // start animation and change text $(selector).animate({ 'margin-left': 0 }, duration, easing, goForth).children('p:first').html(content[contentIndex % content.length]); contentIndex++; // increment index for next time }; // start the sequence goForth(); } </code></pre> <p>Which I call using:</p> <pre><code>var content = [ 'content #1', 'content #2', 'content #3' ]; // if you wish to toggle, just use 2 elements // calling the function startBouncing('#bouncer', content, 2000, 'linear'); </code></pre> <p>And finally, the HTML:</p> <pre><code>&lt;div style="background-color: gray; height: 50px; width: 500px;"&gt; &lt;div id="bouncer" style="background-color: #ff0000; height: 50px; width: 50px;"&gt; &lt;p&gt;content&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>It might not look good, but it works. I haven't spend a second in optimizing the code.</p> <hr> <p><strong>edit</strong></p> <p>I've edited the function so you specify a different duration and easing per side.</p> <pre><code>function startBouncing(selector, content, duration1, duration2, easing1, easing2) { // get the required movement (parent width - element width) var movement = $(selector).parent().width() - $(selector).width(); var contentIndex = 0; // we want to start with content index 0 // define function that makes element go forth var goForth = function() { // start animation and change text $(selector).animate({ 'margin-left': movement }, duration1, easing1, goBack).children('p:first').html(content[contentIndex % content.length]); contentIndex++; // increment index for next time }; // define function that makes element go back var goBack = function() { // start animation and change text $(selector).animate({ 'margin-left': 0 }, duration2, easing2, goForth).children('p:first').html(content[contentIndex % content.length]); contentIndex++; // increment index for next time }; // start the sequence goForth(); } </code></pre> <p>For more advanced easing strings, you should use an plugin that adds more easing strings like <a href="http://gsgd.co.uk/sandbox/jquery/easing/" rel="nofollow">this</a> one.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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