如何更改新闻速递运动方向从左到右
问题描述:
我想从右侧改变新闻股票向左移动,留给正确的,因为我想用阿拉伯文写成,这样重要的是改变运动方向留给对。我想了好几天,但我没有找到任何解决方案如何更改新闻速递运动方向从左到右
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>
答
变化需要的功能abc
作出。
function abc(a,b) {
var marginLefta=(parseInt($("#"+a).css('marginLeft')));
var marginLeftb=(parseInt($("#"+b).css('marginLeft')));
if((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});
}
}
的margin-left
的股票项目需要由+1递增,以左右移动。此外,temp
变量需要在改变为负,因为我们现在从左到右,而不是到左向右(对于文本的开始位置已经改变到相对轴)工作。
+0
现在感谢它的工作 – Beginner
你可以找一个插件,像https://github.com/aamirafridi/jQuery.Marquee它允许您设置一个方向和悬停暂停。 – yuriy636
不是我只是想改变方向从左向右TOR不右边移到左边 – Beginner
这段代码做工精细只想改变运动方向 – Beginner