当前位置: 首页 > article >正文

Layui之可调参数的动态轮播图---好玩的小玩意儿~

 本期精彩:利用Layui制作轮播图

效果图:

前台代码:

 JS代码:

 设置长宽高的事件代码:

//事件
  carousel.on('change(test1)', function(res){
    console.log(res)
  });
  var $ = layui.$, active = {
    set: function(othis){
      var THIS = 'layui-bg-normal'
      ,key = othis.data('key')
      ,options = {};
      othis.css('background-color', '#5FB878').siblings().removeAttr('style'); 
      options[key] = othis.data('value');
      ins3.reload(options);
    }
  };
  
 //监听开关
  form.on('switch(autoplay)', function(){
    ins3.reload({
      autoplay: this.checked
    });
  });
  //输入框的
 $('.demoSet').on('keyup', function(){
    var value = this.value
    ,options = {};
    if(!/^\d+$/.test(value)) return;
    
    options[this.name] = value;
    ins3.reload(options);
  }); 

});

完整代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@ include file="common/heard.jsp" %>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>轮播图</title>
</head>
<body>

 
<div class="layui-carousel" id="test1" lay-filter="test1">
  <div carousel-item="">
    <div><img style="width:700px;height: 400px " src="static/images/t1.jpg"></div>
    <div><img style="width:700px;height: 400px " src="static/images/t2.jpg"></div>
    <div><img style="width:700px;height: 400px " src="static/images/t3.jpg"></div>
    <div><img style="width:700px;height: 400px " src="static/images/t4.jpg"></div>
  </div>
</div> 
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>设定宽高</legend>
</fieldset> 
<div class="layui-form">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">宽高</label>
      <div class="layui-input-inline" style="width: 98px;">
        <input type="tel" name="width" value="600" autocomplete="off" 
        placeholder="width" class="layui-input demoSet">
      </div>
      <div class="layui-input-inline" style="width: 98px;">
        <input type="tel" name="height" value="280" autocomplete="off" 
        placeholder="height" class="layui-input demoSet">
      </div>
    </div>
  </div>
  
  
 <script>
layui.use(['carousel', 'form'], function(){
  var carousel = layui.carousel
  ,form = layui.form;
  

  //设定各种参数
 var ins3 = carousel.render({
    elem: '#test1'
  }); 
  //图片轮播
  carousel.render({
    elem: '#test1'
    ,width: '700px'
    ,height: '400px'
    ,interval: 1111
  });
  
  
  //事件
  carousel.on('change(test1)', function(res){
    console.log(res)
  });
  var $ = layui.$, active = {
    set: function(othis){
      var THIS = 'layui-bg-normal'
      ,key = othis.data('key')
      ,options = {};
      othis.css('background-color', '#5FB878').siblings().removeAttr('style'); 
      options[key] = othis.data('value');
      ins3.reload(options);
    }
  };
  
 //监听开关
  form.on('switch(autoplay)', function(){
    ins3.reload({
      autoplay: this.checked
    });
  });
  //输入框的
 $('.demoSet').on('keyup', function(){
    var value = this.value
    ,options = {};
    if(!/^\d+$/.test(value)) return;
    
    options[this.name] = value;
    ins3.reload(options);
  }); 

});
</script>
</body>
</html>


http://www.kler.cn/a/37152.html

相关文章:

  • 【学习笔记】在Android使用Frida进行https抓包
  • 如何使用chatgpt写文章
  • 组合(力扣)dfs + 回溯 + 剪枝 JAVA
  • 动态内存管理(1)
  • 2023-07-12力扣每日一题
  • 【Rust 基础篇】Rust 中的泛型:结构体和方法
  • android studio 添加并读取json配置文件
  • R-Meta分析与【文献计量分析、贝叶斯、机器学习等】多技术融合实践与拓展进阶
  • 重启Oracle数据库
  • 【代码随想录 | Leetcode | 第二天】数组 | 双指针法 | 相向双指针 | 27
  • Unity Obfuscator
  • Unity 编辑器-创建模板脚本,并自动绑定属性,添加点击事件
  • 第44节:cesium 大雾效果(cesium自带)(含源码+视频)
  • OpenCV 入门教程:Laplacian算子和Canny边缘检测
  • 常见面试题之List集合
  • 列表状态值转换问状态对应文字处理
  • prometheus采集服务的jmx数据,grafana通过dashboard展示jmx数据
  • 大文件切片上传
  • 30多个小程序一键发布——miniprogram-ci
  • 单例模式(Singleton Pattern)