MKK
MKK

Reputation: 2753

How can I make horizontal/vertical scroll animation in/out?

This my current code. This loads all the comments, and show the comments within <p> as the time of video goes by.

The style newsticker is square with border line.

I want to show the comment in it, and slides-in, then slides-out. Just like this here http://spreadthesource.com/sandbox/featurify/

How can I make it possible?
The point is refreshing content of <p> every seconds with onPlay of media.
So loaded comment has to slide-in, and stay there for 5 seconds, and slides out to disappear.

I made DEMO with jsfiddle.

Anyone can show me with code please.

Javascript

jQuery(document).ready(function () {

    $('#video').on('timeupdate',function(e){
        showComments(this.currentTime);
    });

}); 
var comments = [{'time':'10','message':'hello! 10 secs has past'},{'time':'10','message':'hello! 10-2 secs has past'},{'time':'5','message':'hello! 5 secs has past'},{'time':'30','message':'hello! 30 secs has past'}];


function showComments(time){
    var comments = findComments(time);
    $.each(comments,function(i,comment){
        $('p#newsticker').text(comment.message);

        // Show for 5 seconds, then hide the `p` element.
        $('p#newsticker').show().delay(2000).fadeOut();
    });
}

function findComments(time){
    return $.grep(comments, function(item){
      return item.time == time.toFixed();
    });
}

HTML

<body>
    <div class="newsticker"> 
        <p id="newsticker"></p>
    </div>
    <br />
    <br />
    <video id="video" controls="controls" autoplay="autoplay" name="media"><source src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4"></video>
</body>

CSS

div.newsticker{
    border:1px solid #666666;
    width:400px;
    height:50px;
}

Upvotes: 0

Views: 383

Answers (1)

N8FURY
N8FURY

Reputation: 9970

jQuery(document).ready(function () {
    var counter=5;
    $('#video').on('timeupdate',function(e){
        if(this.currentTime > counter){
            showComments(this.currentTime);
            counter+=5; // for updating the comment every after 5 seconds.
        }    
    });

}); 
var comments = [{'time':'10','message':'hello! 10 secs has past'},{'time':'15','message':'hello! 15 secs has past'},{'time':'5','message':'hello! 5 secs has past'},{'time':'20','message':'hello! 20 secs has past'}];


function showComments(time){
    var comments = findComments(time);
    $.each(comments,function(i,comment){
        $('.newsticker p').animate({"marginLeft":"400px","opacity":".0"}, 600).fadeOut(100);
        $('.newsticker').append("<p style='margin-left:400px;opacity:0'>"+comment.message+"</p>");
        $('.newsticker p').animate({"marginLeft":"0px","opacity":"1"}, 600);
    });
}

function findComments(time){
    return $.grep(comments, function(item){
      return item.time == time.toFixed();
    });
}

I have changed your code.Hope this will work for you. you can see the fiddle from here. http://jsfiddle.net/Aveendra/m5tt9/

Upvotes: 1

Related Questions