Home > Web Front-end > JS Tutorial > js implements text vertical scrolling and mouse hover effects_javascript skills

js implements text vertical scrolling and mouse hover effects_javascript skills

WBOY
Release: 2016-05-16 15:22:45
Original
1973 people have browsed it

The example in this article introduces the vertical scrolling effect of text, mainly using the setInterval(function(){}, time); method. It is shared with everyone for your reference. The specific content is as follows
HTML layout:

<ul class="recommend-info">
  <li>
    <span class="push">荐</span>
    <a href="javascript:;">1高档社区,经典户型,机会难得,稍纵即逝!仅售66万!</a>
    <span class="htype">66万  3室2厅1卫 120㎡</span>
  </li>
  <li>
    <span class="push">荐</span>
    <a href="javascript:;">2高档社区,经典户型,机会难得,稍纵即逝!仅售66万!</a>
    <span class="htype">66万  3室2厅1卫 120㎡</span>
  </li>
  <li>
    <span class="push">荐</span>
    <a href="javascript:;">3高档社区,经典户型,机会难得,稍纵即逝!仅售66万!</a>
    <span class="htype">66万  3室2厅1卫 120㎡</span>
  </li>
  <li>
    <span class="push">荐</span>
    <a href="javascript:;">4高档社区,经典户型,机会难得,稍纵即逝!仅售66万!</a>
    <span class="htype">66万  3室2厅1卫 120㎡</span>
  </li>
</ul>
Copy after login

CSS style:

<style>
  .recommend-info {
    width: 630px;
    height: 42px;
    padding: 0 10px;
    margin-top: 12px;
    margin-bottom: 18px;
    border: 1px dashed #DFDFDF;
    overflow: hidden;
  }
  .recommend-info li {
    overflow: hidden;
    font-size: 14px;
    line-height: 42px;
  }
  .recommend-info li .push {
    float: left;
    display: inline-block;
    width: 18px;
    height: 17px;
    margin-top: 12px;
    margin-right: 10px;
    background: #D95B4E;
    font-size: 12px;
    color: #fff;
    text-align: center;
    line-height: 17px;
  }
  .recommend-info li a {
    float: left;
    color: #333;
  }
  .recommend-info li a:hover {
    color: #da5c4f;
  }
  .recommend-info li .htype {
    float: right;
    color: #999;
  }
</style>
Copy after login


JS script:

<script>
  // 不断把新的第一个追加到后面 
  function vscroll() {
    var frtEle = $('.recommend-info li:first');
    frtEle.animate({'marginTop': -$('.recommend-info li').height()}, 500, function(){
      frtEle.css('marginTop', 0);
      $('.recommend-info').append(frtEle);
    });
  }
  var startInterval = setInterval(vscroll, 3000);

  // 鼠标悬停 
  $('.recommend-info li').hover(function(){
    clearInterval(startInterval);
  }, function(){
    startInterval = setInterval(vscroll, 3000);
  });
</script>

Copy after login

The above is the entire content of this article, thank you for your attention!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template