zoukankan      html  css  js  c++  java
  • JQuery-跑马灯(文字无缝向上翻动-封装)

    转载自他人:https://blog.csdn.net/z69183787/article/details/12857587

    1.  
      (function($){
    2.  
      $.fn.extend({
    3.  
      "slideUp":function(value){
    4.  
       
    5.  
      var docthis = this;
    6.  
      //默认参数
    7.  
      value=$.extend({
    8.  
      "li_h":"30",
    9.  
      "time":2000,
    10.  
      "movetime":1000
    11.  
      },value)
    12.  
       
    13.  
      //向上滑动动画
    14.  
      function autoani(){
    15.  
      $("li:first",docthis).animate({"margin-top":-value.li_h},value.movetime,function(){
    16.  
      $(this).css("margin-top",0).appendTo(".line");
    17.  
      })
    18.  
      }
    19.  
       
    20.  
      //自动间隔时间向上滑动
    21.  
      var anifun = setInterval(autoani,value.time);
    22.  
       
    23.  
      //悬停时停止滑动,离开时继续执行
    24.  
      $(docthis).hover(function(){
    25.  
      clearInterval(anifun); //清除自动滑动动画
    26.  
      },function(){
    27.  
      setInterval(autoani,value.time); //继续执行动画
    28.  
      })
    29.  
      }
    30.  
      })
    31.  
      })(jQuery)

    主要思路:

      滑动动画,就是改变元素的位置,要改变元素的位置有两种方法,一种改变left,top属性(相对定位和绝对定位),还有一种,就是现在这里用到的,改变margin的值。

      上例中动画过程:

        1.设置要改变margin-top的值;

        2.用animate方法改变第一个LI的margin-top的值为-30(负值会向上移动);

        3.在动画完成之后,回调函数内,把当前的第一个LI的margin-top改变为"0"

        4.把当前这第一个LI移动到所有LI的最后一个。(实现无缝)

  • 相关阅读:
    [转] linux下查看文件编码及修改编码
    offset Dimensions 详解
    style属性
    Using NodeLists
    Element Children
    Node、Document关系的探究
    Document、HTMLDocument关系的探究
    BOM Summary P268-P269
    Intervals and Timeouts
    Window Position
  • 原文地址:https://www.cnblogs.com/pegasus827/p/9672559.html
Copyright © 2011-2022 走看看