简体   繁体   中英

jquery horizontal news ticker using google jsapi

I need to make some changes to this news ticker which is based on goldyberg's jquery horizontal newsticker using Google JSAPI:

http://inetwebdesign.com/jQueryTools/tickers/horizontal-news-ticker2/horizontal-news-ticker3.html

I have two questions:

  1. How do you limit the number of words that are being pulled into the div? Right now it is too long and it wraps.

  2. How do you add the date from the rss feed to the string that is displayed?

Here is the code I believe is relevant:

     parse: function(entries) {
        var feedMarkup = '';
        feedMarkup += '<ul>';
        for (var i = 0; i < entries.length; i++) {
            feedMarkup += '<li><a target="_blank"
                    href="'+entries[i].link+'">'+entries[i].title+'</a></li>';  
        }   
        feedMarkup += '</ul>';
        $("#ticker-content").empty().append(feedMarkup).fadeIn(400);

        $('#ticker ul                  
                 li:eq(0)').show();                                                   

        current = $('#ticker ul li:eq(0)').index();
        first = 0;
        last = $('#ticker ul li').length;

Thanks in advance for your help.

Regards, umbre

  1. To limit the words, use entries[i].title
  2. To display the date, use entries[i].publishedDate, add a reference to the Datejs open-source JavaScript date library http://www.datejs.com on your HTML file and modify the provided javascript.

A demo is here: http://www.marlenynunez.com/files/jsapi/horizontal-news-ticker4.html

HTML file:

    <script type="text/javascript" src="js/date.js"></script>
    <script type="text/javascript" src="js/scripts.js"></script>

scripts.js file:

    parse: function(entries) {
        var feedMarkup = '';
        var pubDate;
        var titleText;
        var splitText;
        feedMarkup += '<ul>';
        for (var i = 0; i < entries.length; i++) {
            titleText = entries[i].title;
            splitText = titleText.substring(0,60).split(" ");
            titleText = splitText.slice(0, -1).join(" ") + '...';
            pubDate = Date.parse(String(entries[i].publishedDate)).toString('MMM dd');
            feedMarkup += '<li>'+pubDate+' | <a target="_blank" href="'+entries[i].link+'">'+titleText+'</a></li>'; 
        }   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM