最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

jQuery图片轮播的具体实现_jquery

来源:动视网 责编:小采 时间:2020-11-27 21:13:36
文档

jQuery图片轮播的具体实现_jquery

jQuery图片轮播的具体实现_jquery:效果如下: 先看一看html代码,以及对应的css代码: 代码如下: 1 2 3 4 5 代码如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{
推荐度:
导读jQuery图片轮播的具体实现_jquery:效果如下: 先看一看html代码,以及对应的css代码: 代码如下: 1 2 3 4 5 代码如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{
 效果如下:

先看一看html代码,以及对应的css代码:

代码如下:









  • 1

  • 2

  • 3

  • 4

  • 5




  • 代码如下:
    #scrollPics{
    height: 150px;
    width: 100%;
    margin-bottom: 10px;
    overflow: hidden;
    position:relative;
    }
    .num{
    position:absolute;
    right:5px;
    bottom:5px;
    }
    #scrollPics .num li{
    float: left;
    color: #FF7300;
    text-align: center;
    line-height: 16px;
    width: 16px;
    height: 16px;
    cursor: pointer;
    overflow: hidden;
    margin: 3px 1px;
    border: 1px solid #FF7300;
    background-color: #fff;
    }
    #scrollPics .num li.on{
    color: #fff;
    line-height: 21px;
    width: 21px;
    height: 21px;
    font-size: 16px;
    margin: 0 1px;
    border: 0;
    background-color: #FF7300;
    font-weight: bold;
    }

    用绝对定位设置列表 num 的位置,对 li 设置相关样式,on 表示显示图片对应的数字列表中 li 的样式类别。

    接下来是 js 代码:

    代码如下:
    //滚动广告
    var len = $(".num > li").length;
    var index = 0; //图片序号
    var adTimer;
    $(".num li").mouseover(function() {
    index = $(".num li").index(this); //获取鼠标悬浮 li 的index
    showImg(index);
    }).eq(0).mouseover();
    //滑入停止动画,滑出开始动画.
    $('#scrollPics').hover(function() {
    clearInterval(adTimer);
    }, function() {
    adTimer = setInterval(function() {
    showImg(index)
    index++;
    if (index == len) { //最后一张图片之后,转到第一张
    index = 0;
    }
    }, 3000);
    }).trigger("mouseleave");

    function showImg(index) {
    var adHeight = $("#scrollPics>ul>li:first").height();
    $(".slider").stop(true, false).animate({
    "marginTop": -adHeight * index + "px" //改变 marginTop 属性的值达到轮播的效果
    }, 1000);
    $(".num li").removeClass("on")
    .eq(index).addClass("on");
    }

    文档

    jQuery图片轮播的具体实现_jquery

    jQuery图片轮播的具体实现_jquery:效果如下: 先看一看html代码,以及对应的css代码: 代码如下: 1 2 3 4 5 代码如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{
    推荐度:
    标签: 图片 轮播 实现
    • 热门焦点

    最新推荐

    猜你喜欢

    热门推荐

    专题
    Top