Browse Source

我的页面的banner图

master
蟑螂恶霸 3 years ago
parent
commit
d7e152fb0f
  1. 54
      lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/static/project/smallProgram/css/carouselMy.css
  2. 201
      lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/static/project/smallProgram/js/carouselMy.js
  3. 63
      lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/templates/project/smallProgram/image/settings.html

54
lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/static/project/smallProgram/css/carouselMy.css

@ -0,0 +1,54 @@
/*定义css变量*/
:root{
--mywidth: 500px;
--myheight: 100%;
}
*{
margin: 0;
padding: 0;
}
ul{
list-style: none;
}
.carousel-contentMy{
width: var(--mywidth);
height: var(--myheight);
position: relative;
overflow: hidden;
border-radius:10px;
}
.carouselMy{
height: var(--myheight);
position: absolute;
}
.carouselMy li{
float: left;
}
.carouselMy li,.carouselMy li img{
width: var(--mywidth);
height: var(--myheight);
}
.img-indexMy{
position: absolute;
bottom: 8px;
width: 100%;
display: flex;
justify-content: center;
}
.img-indexMy li{
float: left;
width: 18px;
height: 18px;
line-height: 18px;
text-align: center;
border-radius: 10px;
background-color: rgba(0,0,0,0.2);
font-size: 12px;
cursor: pointer;
margin: 0 3px;
color: #fff;
}
.img-indexMy li.js_indexMy,.img-indexMy li:hover{
background-color: rgba(0,0,0,0.7);
}

201
lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/static/project/smallProgram/js/carouselMy.js

@ -0,0 +1,201 @@
(function ($) {
$.fn.carouselMy = function (param) {
var carouselMy = param.carousel, //轮播框架
indexContainer = param.indexContainer, //下标框架
list = $(carouselMy).children("li"), //轮播内容
len = list.length, //轮播内容数量
prev = param.prev, //上翻按钮
next = param.next, //下翻按钮
timing = param.timing, //自动轮播间隔时间
animateTime = param.animateTime, //动画时间
autoPlay = param.autoPlay, //自动播放 true/false
timer, //定时器
index = 1, //索引值
indexListMy, //下标列表
indexClassName = "js_indexMy", //下标高亮类名
action = true, //开始滚动 true/false
totalWidtn = list.width() * (list.length + 2), //轮播框架总宽度
direction = param.direction; //滚动方向
/*初始化*/
for (var i = 1; i <= list.length; i++) {
$(indexContainer).append("<li>" + i + "</li>");
}
$(carouselMy)
.width(totalWidtn)
.append($(list[0]).clone())
.prepend($(list[list.length - 1]).clone())
.css("left", "-" + list.width() + "px");
list = $(carouselMy).children("li");
indexListMy = $(indexContainer).children("li");
$(indexListMy[index - 1]).addClass(indexClassName);
/*判断是否自动播放*/
if (autoPlay) {
startTiming();
$(carouselMy + "," + prev + "," + next + "," + indexContainer).hover(
function () {
window.clearInterval(timer);
},
function () {
startTiming();
}
);
}
/*计时方法*/
function startTiming() {
/*判断方向*/
switch (direction) {
case "right":
timer = window.setInterval("$.rightChangeImg();", timing);
break;
case "left":
timer = window.setInterval("$.leftChangeImg();", timing);
break;
default:
timer = window.setInterval("$.leftChangeImg();", timing);
}
}
/*切换高亮下标*/
$.extend({
changeIndexMy: function (index) {
$(indexListMy).removeClass(indexClassName);
$(indexListMy[index]).addClass(indexClassName);
},
});
/*向左切换图片*/
$.extend({
leftChangeImg: function () {
action = false;
if (index == len) {
index = 0;
$(carouselMy).stop(true, true).css("left", "0px");
}
index++;
$(carouselMy)
.stop(true, true)
.animate(
{
left: "-=" + list.width() + "px",
},
animateTime
);
setTimeout(function () {
if (index == len) {
index = 0;
$(carouselMy).stop(true, true).css("left", "0px");
}
action = true;
}, animateTime);
$.changeIndexMy(index - 1);
},
});
/*向右切换图片*/
$.extend({
rightChangeImg: function () {
action = false;
if (index == 0) {
index = len;
$(carouselMy)
.stop(true, true)
.css("left", "-" + left + "px");
}
index--;
var left = totalWidtn - list.width() * 2;
$(carouselMy)
.stop(true, true)
.animate(
{
left: "+=" + list.width() + "px",
},
animateTime
);
setTimeout(function () {
if (index == 0) {
index = len;
$(carouselMy)
.stop(true, true)
.css("left", "-" + left + "px");
}
action = true;
}, animateTime);
if (index == 0) {
$.changeIndexMy(len - 1);
} else {
$.changeIndexMy(index - 1);
}
},
});
/*下翻点击处理*/
$(next).on("click", function () {
var nowLeft = Math.abs(parseInt($(carouselMy).css("left")));
var left = totalWidtn - list.width() * 2;
if (action) {
if (nowLeft == left) {
index = 0;
$(carouselMy).stop(true, true).css("left", "0px");
}
$.leftChangeImg();
}
});
/*上翻点击处理*/
$(prev).on("click", function () {
var nowLeft = Math.abs(parseInt($(carouselMy).css("left")));
var left = totalWidtn - list.width() * 2;
if (action) {
if (nowLeft == 0) {
index = len;
$(carouselMy)
.stop(true, true)
.css("left", "-" + left + "px");
}
$.rightChangeImg();
}
});
/*下标点击处理*/
indexListMy.on("click", function () {
var no = $(this).index() + 1;
if (action) {
if (no > index) {
$.changeIndexMy(no - 1);
action = false;
var left = (no - index) * list.width();
index = no;
$(carouselMy)
.stop(true, true)
.animate(
{
left: "-=" + left + "px",
},
animateTime
);
setTimeout(function () {
action = true;
}, animateTime);
} else if (no < index) {
$.changeIndexMy(no - 1);
action = false;
var left = (index - no) * list.width();
index = no;
$(carouselMy)
.stop(true, true)
.animate(
{
left: "+=" + left + "px",
},
animateTime
);
setTimeout(function () {
action = true;
}, animateTime);
}
}
});
};
})(jQuery);

63
lib/EmergencyService/zdxtEmergencyBootStart/src/main/resources/templates/project/smallProgram/image/settings.html

@ -4,6 +4,7 @@
<th:block th:include="zdxtInclude :: header('自定义图片')"/>
<link rel="stylesheet" href="/project/smallProgram/css/carousel.css" type="text/css"/>
<link rel="stylesheet" href="/project/smallProgram/css/carouselSite.css" type="text/css"/>
<link rel="stylesheet" href="/project/smallProgram/css/carouselMy.css" type="text/css"/>
<style>
.page-row {
display: flex;
@ -190,19 +191,19 @@
<div class="form-group">
<label class="col-sm-2 control-label is-required">顶部图:</label>
<div class="col-sm-5">
<input id="file-home-banner1" onchange="showImg(this,'site-banner-1')" name="file" type="file" placeholder="图1" multiple>
<input id="file-site-banner1" onchange="showImg(this,'site-banner-1')" name="file" type="file" placeholder="图1" multiple>
</div>
<div class="col-sm-5">
<input id="file-home-banner2" onchange="showImg(this,'site-banner-2')" name="file" type="file" multiple>
<input id="file-site-banner2" onchange="showImg(this,'site-banner-2')" name="file" type="file" multiple>
</div>
</div>
<div class="form-group">
<div class="col-sm-2"></div>
<div class="col-sm-5">
<input id="file-home-banner3" onchange="showImg(this,'site-banner-3')" name="file" type="file" multiple>
<input id="file-site-banner3" onchange="showImg(this,'site-banner-3')" name="file" type="file" multiple>
</div>
<div class="col-sm-5">
<input id="file-home-banner4" onchange="showImg(this,'site-banner-4')" name="file" type="file" multiple>
<input id="file-site-banner4" onchange="showImg(this,'site-banner-4')" name="file" type="file" multiple>
</div>
</div>
</form>
@ -228,9 +229,43 @@
<div class="col-sm-4" style="background: #f1c40f; height: 100%;">3-right</div>
</div>
<div id="tab-4" class="tab-pane">
<div class="col-sm-4" style="background: #0a55a1; height: 100%;">4-left</div>
<div class="col-sm-4" style="background: #0fd115; height: 100%;">4-midden</div>
<div class="col-sm-4" style="background: #f1c40f; height: 100%;">4-right</div>
<div class="page-row" style="height: 756px;">
<div style="height: 100%; width: 60%;">
<form class="form-horizontal m">
<div class="form-group">
<label class="col-sm-2 control-label is-required">banne图:</label>
<div class="col-sm-5">
<input id="file-my-banner1" onchange="showImg(this,'my-banner-1')" name="file" type="file" placeholder="图1" multiple>
</div>
<div class="col-sm-5">
<input id="file-my-banner2" onchange="showImg(this,'my-banner-2')" name="file" type="file" multiple>
</div>
</div>
<div class="form-group">
<div class="col-sm-2"></div>
<div class="col-sm-5">
<input id="file-my-banner3" onchange="showImg(this,'my-banner-3')" name="file" type="file" multiple>
</div>
<div class="col-sm-5">
<input id="file-my-banner4" onchange="showImg(this,'my-banner-4')" name="file" type="file" multiple>
</div>
</div>
</form>
</div>
<div style="height: 100%; width: 40%;">
<div class="box" style="width: 500px; height: 150px;">
<div class="carousel-contentMy">
<ul class="carouselMy">
<li><img id="my-banner-1" name="my-banner-1" width="100%" height="100%"></li>
<li><img id="my-banner-2" name="my-banner-2" width="100%" height="100%"></li>
<li><img id="my-banner-3" name="my-banner-3" width="100%" height="100%"></li>
<li><img id="my-banner-4" name="my-banner-4" width="100%" height="100%"></li>
</ul>
<ul class="img-indexMy"></ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@ -238,6 +273,7 @@
<th:block th:include="zdxtInclude :: footer"/>
<script src="/project/smallProgram/js/carousel.js" type="text/javascript"></script>
<script src="/project/smallProgram/js/carouselSite.js" type="text/javascript"></script>
<script src="/project/smallProgram/js/carouselMy.js" type="text/javascript"></script>
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('custom:image:edit')}]];
var removeFlag = [[${@permission.hasPermi('custom:image:remove')}]];
@ -248,6 +284,7 @@
queryList();
homeBannerPlay();
siteBannerPlay();
myBannerPlay();
});
/** 获取列表 */
@ -305,6 +342,18 @@
});
}
/** 轮播图 */
function myBannerPlay() {
$(".carousel-contentSite").carouselSite({
carousel: ".carouselMy", //轮播图容器
indexContainer: ".img-indexMy", //下标容器
timing: 3000, //自动播放间隔
animateTime: 700, //动画时间
autoPlay: false, //是否自动播放 true/false
direction: "left", //滚动方向 right/left
});
}
/** 显示图片 */
function showImg(fileObj,imgId) {
var file=fileObj.files[0];

Loading…
Cancel
Save