UPDATE
new Fiddle: New JsFiddle
HTML:
<div class="newsticker"> <div class="middle"><p><p></div> </div>
JS:
function transition() { $('.middle').animate({"right":"-100%","opacity":".0"}, 600, function() { $('.middle').first().remove(); }); var width = $('.newsticker').width(); $('.newsticker').append("<div class='middle'><p style='width: " + width + "px;'>Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum</p></div>"); var height = $('.middle p').last().height() / 2; $('.middle p').css('top','-' + height + 'px'); $('.middle').animate({"right":"0px","opacity":"1"}, 600); } setInterval(transition, 2000);
CSS
div.newsticker{ border:1px solid #666666; width:100%; height:100px; padding: 0px; margin: 0px; overflow: hidden; position: relative; } .newsticker p{ padding-left:10px; padding-right:10px; line-height: 1em; padding: 0px; margin: 0px; position: relative; display: block; } .middle {position: absolute; top: 50%; padding:0; margin:0; right: -100%; opacity: 0;}
ORIGINAL RESPONSE
here is a working violin
Jsfiddle
you needed 100px line-height on your p tag, and you needed to reset the padding and margins on your div and p
div.newsticker{ border:1px solid #666666; width:100%; height:100px; padding: 0px; margin: 0px; } .newsticker p{ padding-left:10px; padding-right:10px; float:left; position:absolute; line-height: 100px; padding: 0px; margin: 0px; }
also made some improvements to your animation:
function transition() { $('.newsticker p').animate({"marginLeft":"400px","opacity":".0"}, 600, function() { $('.newsticker p').remove(); $('.newsticker').append("<p style='margin-left:400px;opacity:0'>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam </p>"); $('.newsticker p').animate({"marginLeft":"0px","opacity":"1"}, 600); }); } setInterval(transition, 2000);
you should start with this:
<div class="newsticker"> <p><p> </div>
source share