Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is a working javascript code it's reading from a text file line by line and display each time one line inside the newsTicker jquery plugin and scroll up the lines.

The problem is that when i try to add another code javascript of another or same jquery plugin with another example it's getting mess nothing i scrolling i see text all over the page the two plugins mixed togeather:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://risq.github.io/jquery-advanced-news-ticker/assets/js/jquery.newsTicker.js"></script>
<style>
.newsticker {
    max-width: 620px;
    margin: auto;
}

.newsticker li {
    color: #4e4e4e;
    background: #F2F2F2;
    overflow: hidden;
    height: 28px;
    padding: 10px;
    line-height: 30px;
    list-style: none;
    font-size: 20px;
    text-align: left;
    border-bottom: 1px dotted #2c8162;
}

.newsticker li:hover {
    background: #FFF;
}
</style>
<script>
    var count = 300;
    var counter = setInterval(timer, 1000); //1000 will  run it every 1 second

    function timer() {
    count = count - 1;
    if (count == -1) {
            clearInterval(counter);
            return;
    }

    var seconds = count % 60;
    var minutes = Math.floor(count / 60);
    var hours = Math.floor(minutes / 60);
    minutes %= 60;
    hours %= 60;
    document.getElementById("timer").innerHTML = hours + " Hours " + minutes + " Minutes and " + seconds + " Seconds left untill the next news update."; // watch for spelling
    }
    function news(){
   $('body').find('.newsticker').remove();//It will clear old data if its present 
   var file = "http://newsxpressmedia.com/files/theme/test.txt";
    $.get(file, function (txt) {
            //var lines = txt.responseText.split("\n");
            var lines = txt.split("\n");
            $ul = $('<ul class="newsticker" />');
            for (var i = 0, len = lines.length; i < len; i++) {
                //save(lines[i]); // not sure what this does
                $ul.append('<li>' + lines[i] + '</li>'); //here 
            }
            //$ul.appendTo('body').newsTicker({
            $ul.appendTo('div.wcustomhtml').newsTicker({
                row_height: 48,
                max_rows: 2,
                speed: 6000,
                direction: 'up',
                duration: 1000,
                autostart: 1,
                pauseOnHover: 1
            });
    });
    }
    $(function() {
    news();
    setInterval(function(){
      news();
    },30000)  // it will call every 1 min you can change it
    });
</script>
<br><br><span id="timer"></span><br><br>

This is in JSFiddle i'm not sure why it's not working there maybe i didn't use the code in the right way on JSFiddle: http://jsfiddle.net/chocolade/3LrnH/

This is my site when i use both two javascripts of two plugins:

http://newsxpressmedia.com/test.html

And this is the second javascript im trying to use on my site just under this javascript:

<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js' type='text/javascript'></script>
<script language='JavaScript'>
$(function(){
 $("ul#ticker01").liScroll();
});
/*!
 * liScroll 1.0
 * Examples and documentation at:
 * http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html
 * 2007-2010 Gian Carlo Mingati
 * Version: 1.0.2.1 (22-APRIL-2011)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * Requires:
 * jQuery v1.2.x or later
 *
 */


jQuery.fn.liScroll = function(settings) {
  settings = jQuery.extend({
  travelocity: 0.10
  }, settings);  
  return this.each(function(){
    var $strip = jQuery(this);
    $strip.addClass("newsticker")
    var stripWidth = 1;
    $strip.find("li").each(function(i){
    stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
    });
    var $mask = $strip.wrap("<div class='mask'></div>");
    var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");        
    var containerWidth = $strip.parent().parent().width(); //a.k.a. 'mask' width  
    $strip.width(stripWidth);   
    var totalTravel = stripWidth+containerWidth;
    var defTiming = totalTravel/settings.travelocity; // thanks to Scott Waye  
    function scrollnews(spazio, tempo){
    $strip.animate({left: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
    }
    scrollnews(totalTravel, defTiming);    
    $strip.hover(function(){
    jQuery(this).stop();
    },
    function(){
    var offset = jQuery(this).offset();
    var residualSpace = offset.left + stripWidth;
    var residualTime = residualSpace/settings.travelocity;
    scrollnews(residualSpace, residualTime);
    });   
  }); 
};
</script>

<style>
/* liScroll styles */

.tickercontainer { /* the outer div with the black border */
border: 1px solid #000;
background: #fff;
width: 500px;
height: 27px;
margin: auto 0;
padding: 0;
overflow: hidden;
}
.tickercontainer .mask { /* that serves as a mask. so you get a sort of padding both left and right */
position: relative;
left: 10px;
top: 8px;
width: 500px;
overflow: hidden;
}
ul.newsticker { /* that's your list */
position: relative;
left: 500px;
font: bold 10px Verdana;
list-style-type: none;
margin: 0;
padding: 0;

}
ul.newsticker li {
float: left; /* important: display inline gives incorrect results when you check for elem's width */
margin: 0;
padding: 0;
background: #fff;
}
ul.newsticker a {
white-space: nowrap;
padding: 0;
color: #ff0000;
font: bold 10px Verdana;
margin: 0 50px 0 0;
}
ul.newsticker span {
margin: 0 10px 0 0;
}
</style>

<ul id="ticker01">
 <li><span>10/10/2007</span><a href="#">The first thing ...</a></li>
 <li><span>10/10/2007</span><a href="#">End up doing is ...</a></li>
 <li><span>10/10/2007</span><a href="#">The code that you ...</a></li>
 <!-- eccetera -->
</ul>

Why when using one script it's ok but both on same page making so much mess ?

share|improve this question
1  
You're loading jQuery twice –  adeneo May 2 at 21:21
1  
Don't load jquery.js twice. –  Barmar May 2 at 21:22
1  
this is a great reason to understand what you're doing instead of just copy-paste coding. –  pennstatephil May 2 at 21:23
    
Are you seeing any script errors in the browser console? –  jfriend00 May 2 at 21:30

1 Answer 1

up vote 1 down vote accepted

have you tried using no conflict?

https://api.jquery.com/jQuery.noConflict/

refer to that link, it may be the reason your code gets all messy when using different libraries.

Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. If you need to use another JavaScript library alongside jQuery, return control of $ back to the other library with a call to $.noConflict(). Old references of $ are saved during jQuery initialization; noConflict() simply restores them.

If for some reason two versions of jQuery are loaded (which is not recommended), calling $.noConflict( true ) from the second version will return the globally scoped jQuery variables to those of the first version.

share|improve this answer
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  ssedano May 2 at 23:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.