全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

简单的渐变轮播插件

话不多说,请看代码:

<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Example</title>
    <style>
.CreabineCarousel{
 width: 100%;
  height: 700px;
  background-size: cover;
  position: relative;
}
.CreabineCarousel .CreabineCarousel-dotContainer{
 position:absolute;
 bottom: 5%;
 margin:0 auto;
 z-index: 100;
 list-style-type: none;
 width: 100%;
 text-align: center;
 left: 0;
 padding: 0;
}
.CreabineCarousel .CreabineCarousel-dotContainer .dot{
 width: 30px;
 height: 4px;
 border-radius:3px;
 background-color:#fff;
 display: inline-block;
 margin:0 5px;
 opacity: 0.7;
}
.CreabineCarousel .CreabineCarousel-dotContainer .dot:hover{
 opacity: 1;
}
.CreabineCarousel .CreabineCarousel-item{
 position:absolute;
 width: 100%;
 height: 100%;
 transition:all 0.8s;
}
.CreabineCarousel .CreabineCarousel-item h1{
 max-width: 600px;
 text-align: center;
 font-size: 5rem;
 line-height: 1.3;
 color: #fff;
 padding: 300px 50px 0 50px;
 margin:0 auto;
}
.CreabineCarousel .CreabineCarousel-item p{
 max-width: 600px;
 text-align: center;
 font-size: 1.4rem;
 line-height: 1.4;
 color: #fff;
 padding-top: 10px 50px 0 50px;
 margin:0 auto;
}
    </style>
</head>
<body>
 <div id="carouselRoot"></div>
<script>
function CreabineCarousel(options){
 var imgPathList = options.images;
  var textList = options.contant;
  if (!options.root) {
    throw "require root to this CreabineCarousel";
  }
  if (!imgPathList) {
    throw "must provide parameter images";
  }
  if (imgPathList.length != textList.length) {
    throw "images are not equal to contants";
  }
  var changeCount = 0;
  var timer;
  var _autoScroll = options.autoScroll || false;
  var _scrollDuration = options.scrollDuration || 4000;
  var _height = options.height || 700;

  function initElements() {
   var _root = document.getElementById(options.root);
   if (!_root) {
      throw "no exist called this name element,please create element called this name";
    }
    _root.className = "CreabineCarousel";
    _root.style.height = _height + "px";
    var _dotContainer = document.createElement("ul");
    _dotContainer.className = 'CreabineCarousel-dotContainer';
    _root.appendChild(_dotContainer);
    for (var i = 0; i < imgPathList.length; i++) {
      var _dot = document.createElement("li");
      _dot.className = "dot";
      _dot.id = "item" + (i+1) + "dot";
      _dotContainer.appendChild(_dot);
      var _item = document.createElement("div");
      _item.className = "CreabineCarousel-item"
      _item.id = "item" + (i+1);
      _item.style.backgroundImage = "url(" + imgPathList[i] + ")";
      _item.style.backgroundSize = "cover";
      _item.style.backgroundRepeat = "no-repeat";
      if(i == 0){
        _item.style.opacity = '0';
        _item.style.zIndex = '1';
      }
      _root.appendChild(_item);
      var _h = document.createElement("h1");
      _h.innerText = textList[i].title;
      _item.appendChild(_h);
      var _p = document.createElement("p");
      _p.innerText = textList[i].text;
      _item.appendChild(_p);
    }
    _dotContainer.addEventListener("mouseover",function(e){
     if( e.target && e.target.className == "dot" ){
     clearInterval(timer);
     var id = e.target.id.substring(0,5);
     CarouselHover(id);
     }
    });
    _dotContainer.addEventListener("mouseout",function(e){
     if( e.target && e.target.className == "dot" ){
     var id = e.target.id;
     CarouselOut(id);
     }
    });
    if(_autoScroll){
      timer = setInterval(function(){Carousel()},_scrollDuration);
    }
  }
  function Carousel(){
    var all = document.getElementsByClassName('CreabineCarousel-item');
    for (var i = all.length - 1; i >= 0; i--) {
      all[i].style.opacity = '0';
      all[i].style.zIndex = '1';
    }
    var i=((changeCount++%5)+1);
    var id = "item" + i;
    document.getElementById(id).style.opacity = '1';
    document.getElementById(id).style.zIndex = '10';
  }
  function CarouselHover(id){
    clearInterval(timer);
    var all = document.getElementsByClassName('CreabineCarousel-item');
    for (var i = all.length - 1; i >= 0; i--) {
      all[i].style.opacity = '0';
      all[i].style.zIndex = '1';
    }
    document.getElementById(id).style.opacity = '1';
    document.getElementById(id).style.zIndex = '10';
  }
  function CarouselOut(id){
    var num = id.substring(4,5);
    num = parseInt(num)-1;
    changeCount = num;
    timer = window.setInterval(function(){Carousel()},_scrollDuration);
  }
  initElements();
 new CreabineCarousel({
 root:'carouselRoot',
 autoScroll:true,
        scrollDuration:3000,
 height:700,
 images:['https://cdn.worktile.com/images/index/index_all_bg_1.jpg?v=4.5.18','https://cdn.worktile.com/images/index/index_all_bg_2.jpg?v=4.5.18','https://cdn.worktile.com/images/index/index_all_bg_3.jpg?v=4.5.18','https://cdn.worktile.com/images/index/index_all_bg_4.jpg?v=4.5.18','https://cdn.worktile.com/images/index/index_all_bg_5.jpg?v=4.5.18'],
 contant:[
  {
  title:"title-1",
  text:"text-111"
  },
  {
  title:"title-2",
  text:"text-222"
  },
  {
  title:"title-3",
  text:"text-333"
  },
  {
  title:"title-4",
  text:"text-444"
  },
  {
  title:"title-5",
  text:"text-555"
  },
 ]
 });
</script>
</body>
</html>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!


# 渐变  # 轮播  # 插件  # jQuery简单自定义图片轮播插件及用法示例  # jQuery自适应轮播图插件Swiper用法示例  # jQuery的图片轮播插件PgwSlideshow使用详解  # Bootstrap 最常用的JS插件系列总结(图片轮播、标签切换等)  # Bootstrap轮播插件中图片变形的终极解决方案 使用jqthumb.js  # BootStrap 轮播插件(carousel)支持左右手势滑动的方法(三种)  # 第十篇BootStrap轮播插件使用详解  # jQuery插件实现图片轮播特效  # jQuery图片轮播插件——前端开发必看  # jquery插件tytabs.jquery.min.js实现渐变TAB选项卡效果  # 多说  # hover  # item  # opacity  # transition  # max  # block  # border  # padding  # dot  # radius  # display  # inline  # color  # fff  # carouselRoot  # script  # div  # id  # function 


相关文章: 建站之星代理如何获取技术支持?  潍坊网站制作公司有哪些,潍坊哪家招聘网站好?  深圳网站制作设计招聘,关于服装设计的流行趋势,哪里的资料比较全面?  南京做网站制作公司,南京哈发网络有限公司,公司怎么样,做网页美工DIV+CSS待遇怎么样?  Java解压缩zip - 解压缩多个文件或文件夹实例  番禺网站制作公司哪家值得合作,番禺图书馆新馆开放了吗?  建站主机选虚拟主机还是云服务器更好?  如何快速上传建站程序避免常见错误?  视频网站制作教程,怎么样制作优酷网的小视频?  Android使用GridView实现日历的简单功能  建站之星北京办公室:智能建站系统与小程序生成方案解析  如何将凡科建站内容保存为本地文件?  实例解析Array和String方法  如何高效利用亚马逊云主机搭建企业网站?  青岛网站建设如何选择本地服务器?  如何登录建站主机?访问步骤全解析  如何在云主机快速搭建网站站点?  如何在阿里云购买域名并搭建网站?  制作网站的网址是什么,请问后缀为.com和.com.cn还有.cn的这三种网站是分别是什么类型的网站?  深圳企业网站制作设计,在深圳如何网上全流程注册公司?  南宁网站建设制作定制,南宁网站建设可以定制吗?  表情包在线制作网站免费,表情包怎么弄?  如何在Mac上搭建Golang开发环境_使用Homebrew安装和管理Go版本  如何快速搭建高效香港服务器网站?  如何快速搭建高效服务器建站系统?  如何在云指建站中生成FTP站点?  哪家制作企业网站好,开办像阿里巴巴那样的网络公司和网站要怎么做?  如何快速搭建FTP站点实现文件共享?  网站制作话术技巧,网站推广做的好怎么话术?  如何选择高效稳定的ISP建站解决方案?  家庭建站与云服务器建站,如何选择更优?  兔展官网 在线制作,怎样制作微信请帖?  独立制作一个网站多少钱,建立网站需要花多少钱?  制作旅游网站html,怎样注册旅游网站?  黑客入侵网站服务器的常见手法有哪些?  javascript中对象的定义、使用以及对象和原型链操作小结  制作网站的软件下载免费,今日头条开宝箱老是需要下载怎么回事?  c# 在ASP.NET Core中管理和取消后台任务  如何用PHP快速搭建高效网站?分步指南  如何在IIS服务器上快速部署高效网站?  中山网站推广排名,中山信息港登录入口?  建站之星Pro快速搭建教程:模板选择与功能配置指南  如何用免费手机建站系统零基础打造专业网站?  北京建设网站制作公司,北京古代建筑博物馆预约官网?  C++ static_cast和dynamic_cast区别_C++静态转换与动态类型安全转换  微信小程序 input输入框控件详解及实例(多种示例)  如何快速搭建支持数据库操作的智能建站平台?  如何基于云服务器快速搭建网站及云盘系统?  如何快速打造个性化非模板自助建站?  如何通过虚拟主机快速搭建个人网站? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。