1
我想從右側改變新聞股票向左移動,留給正確的,因爲我想用阿拉伯文寫成,這樣重要的是改變運動方向留給對。我想了好幾天,但我沒有找到任何解決方案如何更改新聞速遞運動方向從左到右
HTML:
$('#ticker2').html($('#ticker1').html());
var temp=0,intervalId=0;
$('#ticker1 li').each(function(){
var offset=$(this).offset();
var offsetLeft=offset.left;
$(this).css({'left':offsetLeft+temp});
temp=$(this).width()+temp+10;
});
$('#ticker1').css({'width':temp+40, 'margin-left':'20px'});
temp=0;
$('#ticker2 li').each(function(){
var offset=$(this).offset();
var offsetLeft=offset.left;
$(this).css({'left':offsetLeft+temp});
temp=$(this).width()+temp+10;
});
$('#ticker2').css({'width':temp+40,'margin-left':temp+40});
function abc(a,b) {
var marginLefta=(parseInt($("#"+a).css('marginLeft')));
var marginLeftb=(parseInt($("#"+b).css('marginLeft')));
if((-marginLefta<=$("#"+a).width())&&(-marginLefta<=$("#"+a).width())){
$("#"+a).css({'margin-left':(marginLefta-1)+'px'});
} else {
$("#"+a).css({'margin-left':temp});
}
if((-marginLeftb<=$("#"+b).width())){
$("#"+b).css({'margin-left':(marginLeftb-1)+'px'});
} else {
$("#"+b).css({'margin-left':temp});
}
}
function start() { intervalId = window.setInterval(function() { abc('ticker1','ticker2'); }, 10) }
$(function(){
$('#news_ticker').mouseenter(function() { window.clearInterval(intervalId); });
$('#news_ticker').mouseleave(function() { start(); })
start();
});
.news {
color: #0065b3;
border-left: 1px solid #0065b3;
border-bottom: 1px solid #0065b3;
font-family: 'Cairo', sans-serif;
}
#ticker1 li, #ticker2 li {
list-style-type:none;
float:left;
padding-right:20px;
position:absolute;
left:0px;
}
#ticker1, #ticker2 {
position:relative;
display:block;
width:4000px;
margin:0;
content=""; display:table;
height:0px;
}
#news_ticker{
height:37px;
overflow:hidden;
color: #0065b3 !important;
border-bottom: 1px solid #0065b3;
border-left: 1px solid #0065b3;
font-family: 'Cairo', sans-serif;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="news_ticker">
<div id ="ticker1" class="w3-col l9 m8 s8 w3-center w3-xlarge">
<li><a href="#"> العنصر الأول </a></li>
<li><a href="#"> العنصر الثاني </a></li>
<li><a href="#"> العنصر الثالث </a></li>
<li><a href="#"> العنصر الرابع </a></li>
<li><a href="#"> العنصر الخامس </a></li>
</div>
<div id="ticker2" class="w3-col l9 m8 s8 w3-center w3-xlarge "></div>
</div>
你可以找一個插件,像https://github.com/aamirafridi/jQuery.Marquee它允許您設置一個方向和懸停暫停。 – yuriy636
不是我只是想改變方向從左向右TOR不右邊移到左邊 – Beginner
這段代碼做工精細只想改變運動方向 – Beginner