发布于2025-01-19 20:58 阅读(1004) 评论(0) 点赞(8) 收藏(3)
单击按钮时,我尝试将 (my-images 类) 的前面元素 (image-1) 移到类的后面,然后将元素上移。到目前为止,这就是我所做的,但它没有起到什么作用。知道我可能做错了什么吗?
HTML
<div class="elegant">
<button class="button" onclick="leftFunction()">Button</button>
<div class="my-image" id="image-1">
<div class="banner">
<h1 class=imageLetters>Blue</h1>
</div>
</div>
<div class="my-image" id="image-2">
<div class="banner">
<h1 class=imageLetters>Red</h1>
</div>
</div>
<div class="my-image" id="image-3">
<div class="banner">
<h1 class=imageLetters>Yellow</h1>
</div>
</div>
<button class="button">Button</button>
</div>
JQuery
x = 0;
function leftFunction() {
x++;
var count = $(".my-image").length;
if (x > count) {
x = 0;
}
var image = document.getElementById("image-" + x);
image.style.display = "none";
$("image-" + x).append($(".my-image"));
image.style.display = "block";
}
CSS
.elegant {
background: #800000;
display: flex;
align-items: left;
justify-content: center;
height: 100%;
}
.button {
background-color: #4caf50;
border: none;
color: white;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
height: 100px;
width: 100px;
align-self: center;
}
.banner {
display: flex;
margin: 0;
z-index: 12;
width: 40px;
height: 300px;
background: rgba(255, 255, 255, 1);
color: black;
mix-blend-mode: lighten;
padding-bottom: 10px;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1, 1);
}
#image-1 {
padding-left: 10px;
height: 555px;
width: 50px;
top: 150px;
left: 400px;
background-image: url("https://images.pexels.com/photos/949129/pexels-photo-949129.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
background-size: 1100px 700px;
background-position: -60px -20px;
z-index: 4;
margin-bottom: 20px;
margin-top: 150px;
-webkit-transition: -webkit-transform 0.4s;
transition: transform 0.4s;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1, 1);
}
#image-1:hover {
-moz-transform: scale(1.03);
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
#image-2 {
padding-left: 10px;
height: 560px;
width: 100px;
box-shadow: 0px 0px 25px rgba(0, 0, 0, 0.5);
top: 150px;
left: 400px;
background-image: url("https://images.pexels.com/photos/949129/pexels-photo-949129.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
background-size: 1100px 700px;
background-position: -170px -20px;
z-index: 5;
margin-bottom: 20px;
margin-top: 150px;
-webkit-transition: -webkit-transform 0.4s;
transition: transform 0.4s;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1, 1);
}
#image-2:hover {
-moz-transform: scale(1.03);
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
#image-3 {
padding-left: 10px;
height: 565px;
width: 150px;
box-shadow: 0px 0px 25px rgba(0, 0, 0, 0.5);
top: 150px;
left: 400px;
background-image: url("https://images.pexels.com/photos/949129/pexels-photo-949129.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940");
background-size: 1100px 700px;
background-position: -280px -20px;
z-index: 6;
margin-bottom: 20px;
margin-top: 150px;
-webkit-transition: -webkit-transform 0.4s;
transition: transform 0.4s;
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0) scale(1, 1);
}
#image-3:hover {
-moz-transform: scale(1.03);
-webkit-transform: scale(1.03);
transform: scale(1.03);
}
这是我制作的 codepen 示例https://codepen.io/Angatvir/pen/mjxjxd
试试这个代码:
function leftFunction() {
var e = $('.my-image');
e.eq(0).insertAfter( e.eq(e.length - 1) )
}
https://codepen.io/vommbat/pen/VBXEOG
代码已更新(codepen 也已更新)
淡出和淡入:
function leftFunction() {
var e = $('.my-image');
e.eq(0).animate({
opacity: 0
}, 1000, function() {
$(this).insertAfter( e.eq(e.length - 1) ).animate({
opacity: 1
}, 1000)
});
}
作者:黑洞官方问答小能手
链接:http://www.qianduanheidong.com/blog/article/538724/4d67be3a8fb530fcc56d/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!