导航首页 » 技术教程 » jquery实现文字单行横移或翻转(上下、左右跳转)
jquery实现文字单行横移或翻转(上下、左右跳转) 109 2024-02-06   

通过jquery的animate实现上下单行自动跳转

 <script type="text/javascript" src="http://www.gimoo.net/t/1808/__ROOT__/Style/H/js/jquery-1.7.2.min.js"></script>
<style>
  .rool-div{
    height:50px;
    width:700px;
    margin:0 auto;
    position: relative;
    overflow: hidden;
    border:2px solid red;
  }
  .roll{
    height:50px;
    width:700px;
    margin:0 auto;
  }
  .roll span{
    display:block;
    height:50px;
    width:700px;
    line-height:50px;
  }
  a {
    text-decoration:none;
     display:inline-block;
 }
</style>
<div class="rool-div">
 <div class="roll" id="roll">
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">1. Lorem Ipsum is simply dummy text of the printing and typesetting industry</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">2. It is a long established fact that a reader will be distracted</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">3. Many desktop publishing packages</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">4. All the Lorem Ipsum generators on the Internet tend to repeat predefined</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">5. The standard chunk of Lorem Ipsum used</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">6. English versions from the 1914 translation by H. Rackham.</a></span>
   <span><a href="http://www.gimoo.net/t/1808/5b66a95a61550.html">7. Bu metin deneme amaçlıdır the standard chunk of Lorem Ipsum used</a></span>
 </div>
</div>
<script>
  (function($){
    $.fn.extend({
      Roll:function(){
        return this.each(function(){
          var n=0;
          $('#roll span a').hover(function(){
            $(this).css('color','red');
          },function(){
            $(this).css('color','green');
          });
          var timername=setInterval(function(){Play()},1000);
          $("#roll").hover(
              function()
              {
                clearInterval(timername);
              },
              function()
              {
              timername=setInterval(function(){Play()},1000);
              });
          function Play(){
            if($("#roll>span").length>n)
              n++;
            else
              n=1;
            $("#roll").animate({'marginTop':-($("#roll span" ).height())*(n-1)});
          }
        });
      }
    })
  })(jQuery);
</script>

二 通过scrollLeft函数实现自动左右移动(谷歌浏览器偶尔不能移动)

<style type="text/css">
#demo {overflow:hidden;width:740px; }
#indemo { float: left; width: 800%;}
#demo1 { float: left; }
#demo2 { float: left;margin-left:7px;}
</style>
<script src="http://www.gimoo.net/t/1808/bootstrap-3.3.5-dist/js/jquery-1.11.3.js"></script>
<div id="demo">
  <div id="indemo">
    <div id="demo1">
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
      <a href="http://www.gimoo.net/t/1808/5b66a95a61550.html"><img src="http://www.gimoo.net/t/1808/zhuanpan/images/pointer.png" alt="#" /></a>
    </div>
    <div id="demo2"></div>
  </div>
</div>
<script>
var speed=10;
var tab=document.getElementById("demo");
var tab1=document.getElementById("demo1");
var tab2=document.getElementById("demo2");
$("#demo2").text($("#demo1").clone());
$("#demo2").clone();
function Marquee(){
  if(tab2.offsetWidth-tab.scrollLeft<=0)
  tab.scrollLeft-=tab1.offsetWidth
  else{
  tab.scrollLeft++;
  }
}
var MyMar=setInterval(Marquee,speed);
tab.onmouseover=function() {clearInterval(MyMar)};
tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};
</script>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持绿夏网!



!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103