• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
余苏益
博客园    首页    新随笔    联系   管理    订阅  订阅
11.16

overflow: hidden;在父元素上设置,子元素就不会超出父元素

 

轮播图
$(function(){
    var current=0;
    var count=$(".pics-list>li").length;
    //移动的方法
    function move(){
//执行方法 
        $(".points-list>li").eq(current).addClass("active").siblings().removeClass("active");
        $(".pics-list").css("left",-1200*current+"px");
    }
     //点击右箭头时起作用
    function next(){
        if(current<count-1){
            current++;
        }else{
            current=0;
        }
          move();
    }
         //鼠标移入移出时 定时器显示  移入 起作用 移出 不起作用(不需要定时器)
      var timer=setInterval(() => {
           next();
        }, 3000);
             鼠标悬浮hover时方法   鼠标放上去自动轮播时间停止 
             $(".banner-box ").hover(function(){
               clearInterval(timer);
             },function(){
                timer=setInterval(() => {
                    next();
                 }, 3000);
             })
             
    //点击点的方法   点击点时 自动轮播到图片
    $(".points-list>li").click(function(){
        current=$(this).index();
        move();
    })
    $(".buts>.next").click(function(){
         next();
    })
  //点击左箭头时起作用
    $(".buts>.prev").click(function(){
        if(current>0){
            current--;
        }else{
            current=count-1;
        }
        move();
    })
})
$(function(){
    $(".top-list .title").click(function(){
        $(this).addClass("active").siblings().removeClass("active");
        $(".top-list-main ul").eq((this).index()).show().siblings().hide();
    })
})
设置时间
  • setInterval() - 间隔指定的毫秒数不停地执行指定的代码。
  • setTimeout() - 在指定的毫秒数后执行指定代码。
  • clearInterval() 方法用于停止 setInterval() 方法执行的函数代码。
posted on 2021-11-17 13:37  余苏益  阅读(29)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3