jquery标题左右移动动画

本文介绍了一个使用HTML, CSS和jQuery实现的菜单标题动画效果。该效果使得标题在指定范围内左右移动,通过设置动画时间和回调函数来实现循环播放,为用户提供了一种新颖的视觉体验。
标题会在红框范围内来回移动

这里写图片描述

html和css代码
<div class="menu-notice" @click="check_cart">
        <div class="menu-notice-logo"></div>
        <div class="menu-notice-title" ref="noticeTitle">
          {{storeinfo[0] ? storeinfo[0]['name'] : ''}}
        </div>
      </div>
.menu-container .menu-notice{
  height: 45px;
  line-height: 45px;
  background: #fff9df;
  position: relative;
}
.menu-container .menu-notice:after{
  content: "";
  display: block;
  width: 0;
  height: 0;
  visibility: hidden;
  clear: both;
}
.menu-notice .menu-notice-logo,.menu-notice .menu-notice-title{
  float: left;
  height: 45px;
}
.menu-notice .menu-notice-logo{
  width: 50px;
  background: url("../../assets/notice2.png") no-repeat center center;
  background-size: 50%;
}
.menu-notice .menu-notice-title{
  position: absolute;
  left: 50px;
  top: 0px;
  font-size: 15px;
  color: #666;
  font-weight: 600;
}
jquery代码
blockMove: function () {
      let that = this;
      let noticeTitle = this.$refs.noticeTitle.offsetWidth ? this.$refs.noticeTitle.offsetWidth : 100;
      let menuContainer = this.$refs.menuContainer.clientWidth - (20 + noticeTitle);
      if($('.menu-notice-title').position().left == 50){
          $('.menu-notice-title').stop().animate({
            left: menuContainer
          },15000,function () {
            that.blockMove();
          })
      }else{
          $('.menu-notice-title').stop().animate({
            left: '50px'
          },15000,function () {
            that.blockMove();
          })
      }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值