0

jQuery Marquee with CSS3 Support

Ad
jquery-marquee

Download   Demo

jQuery-Marquee is a lightweight jQuery plugin to scroll the text like the old traditional marquee.

1. INCLUDE JS FILES

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
<script src="//rawgithub.com/tobia/Pause/master/jquery.pause.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" type="text/javascript"></script>
<script src="//rawgithub.com/aamirafridi/jQuery.Marquee/master/jquery.marquee.min.js?v=4" type="text/javascript"></script>

2.  HTML

<div class='marquee'>Lorem ipsum dolor sit amet, consectetur adipiscing elit END.</div>

3. CSS

.marquee {
  width: 300px; /* the plugin works for responsive layouts so width is not necessary */
  overflow: hidden;
  border:1px solid #ccc;
}

4. JAVASCRIPT

$('.marquee').marquee({
    //speed in milliseconds of the marquee
    duration: 15000,
    //gap in pixels between the tickers
    gap: 50,
    //time in milliseconds before the marquee will start animating
    delayBeforeStart: 0,
    //'left' or 'right'
    direction: 'left',
    //true or false - should the marquee be duplicated to show an effect of continues flow
    duplicated: true
});

5. OPTIONS

  • allowCss3Support If you wish the plugin should animate always using jQuery animate method even if browser supporst CSS3 animations. Default is true
  • css3easing Works when allowCss3Support is set to true – for full list see:http://www.w3.org/TR/2013/WD-css3-transitions-20131119/#transition-timing-function . Default is’linear’
  • easing Requires jQuery easing plugin http://gsgd.co.uk/sandbox/jquery/easing/. Default is’linear’
  • delayBeforeStart Time in milliseconds before the marquee starts animating. Default is 1000
  • direction Direction towards which the marquee will animate ‘left’ / ‘right’ / ‘up’ / ‘down’. Default is ‘left’. Todo: need to change this to ltr/rtl etc
  • duplicated Should the marquee be duplicated to show an effect of continuous flow. Use this only with the text is shorter than the container. Default is false
  • duration Duration in milliseconds in which you want your element to travel. Default is 5000. This option is the old speed option which still works but duration is the more correct word.
  • gap Gap in pixels between the tickers. Will work only when the duplicated option is set to true. Default is 20. Note: 20 means 20px so no need to use ’20px’ as the value.
  • pauseOnHover On hover pause the marquee. If browser supports CSS3 and allowCss3Support is set to true than it will be done using CSS3. Otherwise this will be done using jQuery pluginhttps://github.com/tobia/Pause. Default is false. Check the demo page for a demo.
  • pauseOnCycle On cycle, pause the marquee for delayBeforeStart milliseconds.

6. EVENTS

  • beforeStarting: Event will be fired on the element before animation starts.
  • finished: Event will be fired on the element after the animation finishes.
  • paused: Event will be fired on the element when the animation is paused.
  • resumed: Event will be fired on the element when the animation is resumed.

7. METHODS

These methods can be used like this:

  • First initialize marquee with any options var $mq = $(‘.marquee’).marquee();
  • Then at any time you can call following methods var $mq.marquee(‘NAME-OF-METHOD-AS-STRING’);

Here is the list of all methods:

  • pause: To pause the marquee at any time.
  • resume: To resume the marquee after being paused previously.
  • toggle: To toggle between pause and resume methods.
  • destroy: To remove marquee plugin from your element. This method is useful if you are loading/changing the data using Ajax or just another string. You can combine this with finishedevent so you can let marquee to show some data and soon it finishes showing, you can destroy it, change the html and than apply the plugin again. See the demo page for details (links provided above).

8. EXAMPLES

How to use methods:

var $mq = $('.marquee').marquee();
$('.someLink').click(function(){
  $mq.marquee('pause/resume/toggle');
});

Change content and re-apply the plugin.

$('.marquee')
    .bind('finished', function(){
        //Change text to something else after first loop finishes
        $(this).marquee('destroy');
        //Load new content using Ajax and update the marquee container
        $(this).html('Some new data loaded using ajax')
            //Apply marquee plugin again
            .marquee()
    })
    .marquee();

 

How to use events:

$('.marquee')
    .bind('beforeStarting', function () {
        //code you want to execute before starting the animations
    })
    .bind('finished', function () {
        //code you want to execute before after each animation loop
    })
    //Apply plugin
    .marquee({
        duration: 2000
    });
Filed in: Css / Css3 Plugins & Demos, HTML / HTML5 Plugins & Demos, Jquery Plugins & Demos, Menu & Navigation Tags: , , , , ,
Ad

Get Updates

Share This Post

Recent Posts

Ad

Leave a Reply

You must be Logged in to post comment.

© 2016 Html Use. All rights reserved.