gpt4 book ai didi

javascript - 如何在单击时淡出 1 张图片并自动淡入彼此靠近的 4 张图片?

转载 作者:行者123 更新时间:2023-11-28 19:28:46 27 4
gpt4 key购买 nike

我想单击已有的图片,然后再淡入 4 张图片。像过滤一样的东西。例如,我正在尝试选择混凝土作为主要类别,然后我想再接收 4 张带有用户想要选择的公斤的图片淡入。

$(document).ready(function() {

$(".pulse-button").click(function() {

$(this).addClass('fadeOut');

});

});

//END BUTTON FADEOUT

$('button').on('click', function() {

$(this).prop('disabled', true);

}); //END BUTTON DISABLE


//START OF PLASTER-BOARD FADE-IN FUNCTIONALITY

$(".pulse-button").click(function() {

$("#plasterBoard").fadeToggle("slow", "linear", "complete");

});

//END OF PLASTER-BOARD FADE-IN FUNCTIONALITY

/////////////////////////////////////////////////////////////////////

//START OF BRICK FADE-IN FUNCTIONALITY

$(".pulse-button").click(function() {

$("#brick").fadeToggle("slow", "linear", "complete");

});

//END OF BRICK FADE-IN FUNCTIONALITY

/////////////////////////////////////////////////////////////////////

//START OF CONCRETE STONE FADE-IN FUNCTIONALITY

$(".pulse-button").click(function() {

$("#concreteStone").fadeToggle("slow", "linear", "complete");

});

//END OF CONCRETE STONE FADE-IN FUNCTIONALITY

/////////////////////////////////////////////////////////////////////

//START OF CONCRETE STONE FADE-IN FUNCTIONALITY

$(".pulse-button").click(function() {

$("#aerateConcrete").fadeToggle("slow", "linear", "complete");

});

//END OF CONCRETE STONE FADE-IN FUNCTIONALITY

/////////////////////////////////////////////////////////////////////


$("#plasterBoard").click(function() {

$("#plasterBoard").fadeOut(300);
$("#kilosIcon").fadeIn(300);
$("#KILOIcon").fadeIn(300);
});

$("#brick").click(function() {

$("#brick").fadeOut(300);

$("#kilosIcon").fadeIn(300);

});

$("#concreteStone").click(function() {

$("#concreteStone").fadeOut(300);

$("#kilosIcon").fadeIn(300);

});

$("#aerateConcrete").click(function() {

$("#aerateConcrete").fadeOut(300);

$("#kilosIcon").fadeIn(300);

});
* {
margin: 0;
padding: 0;
}

.fadeOut {
opacity: 0;
}

.pulse-button {
transition: all .5s linear;
position: fixed;
width: 200px;
height: 200px;
border: none;
box-shadow: 0 0 0 0 rgba(232, 76, 61, 0.7);
border-radius: 50%;
background-color: #e84c3d;
color: white;
background-size: auto;
background-repeat: no-repeat;
cursor: pointer;
-webkit-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
-moz-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
-ms-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
position: absolute;
display: inline-block;
top: 50%;
left: 50%;
line-height: 40px;
margin-top: -50px;
margin-left: -50px;
}

.pulse-button:hover {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}

@-webkit-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@-moz-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@-ms-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}


/* BACKGROUND */

.hero-image {
background: url(imgs/sajad-mohammadi-1159479-unsplash.jpg) no-repeat center;
background-size: cover;
height: 100%;
!important position: relative;
}


/*----------*/

.column {
float: left;
width: 25%;
padding: 5px;
margin-top: 470;
flex: 25%;
padding: 5px;
}

.row {
display: flex;
}

.row::after {
content: "";
clear: both;
display: table;
}

@media screen and (max-width: 500px) {
.column {
width: 100%;
}
}

#kilosIcon {
margin-top: 470px;
}

.imgBorder {
padding: 15px 205px 0 205px;
background-color: white;
box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
-moz-box-shadow: 0 1px 2px rgba(34, 25, 25, 0.4);
-webkit-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script type=”text/javascript” src=https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<!-- CC -->

<!-- END OF STYLE -->

<!-- END OF HEAD -->

<!-- ///////////////////////////////////////////////////////////////////// BODY ///////////////////////////////////////////////////////////////////// -->

<body>
<!-- START of BODY -->

<div>
<!-- START BUTTON -->

<button id="pulseButton" class="pulse-button" class="container" style="align-content: center; outline: none;">

<h1>START</h1>

<!-- START BUTTON FADEOUT -->



<!-- ------------------------END OF LAYER 1 FADE IN PICTURES FUNTIONALITIES ---------------------------- -->

</button>
<!-- END OF BUTTON FUNCTIONALITIES -->

</div>
<!-- END START BUTTON -->

<!-- ------------------------------------------------------------------------------------- -->

<!-- ------------------------------------------------------------------------------------- -->

<!-- ------------------------------------------------------------------------------------- -->

<div class="hero-image">
<!-- CONTAINER OF 1st LAYER PICTURES DIV -->

<img id="kilosIcon" src="imgs/10kilo.png" alt="aerateConcrete" class="imgBorder" style="width:25%; display: none; ">

<!-- Small IMAGES from Filters -->

<div class="row">

<div class="column">
<!-- PICTURE 1 FADE OUT -->

<img id="plasterBoard" src="imgs/Plasterboard.jpeg" alt="plasterboard" class="imgBorder" style="width:100%; display: none;">

<!-- Fading in IMAGES on CLICK OF ANOTHER IMAGE -->


</div>

<div class="column">
<!-- PICTURE 2 FADE OUT -->

<img id="brick" src="imgs/brick.jpeg" alt="brick" class="imgBorder" style="width:100%; display: none;">

</div>

<div class="column">
<!-- PICTURE 3 FADE OUT -->

<img id="concreteStone" src="imgs/concrete(stone).jpeg" alt="concreteStone" class="imgBorder" style="width:100%; display: none;">

<!-- FADING IN IMAGES ON CLICK OF ANOTHER IMAGE -->

</div>

<div class="column">
<!-- PICTURE 4 FADE OUT -->

<img id="aerateConcrete" src="imgs/aeratedConcrete.jpg" alt="aerateConcrete" class="imgBorder" style="width:50%; display: none;">

</div>

</div>
<!-- END OF PICTURE ROW AFTER CLICK -->

</div>
<!-- END CONTAINER OF 1st LAYER PICTURES DIV -->

<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->

<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->
<!-- START OF 3RD LAYER FOR KILO SPECIFICATION PICTURES -->

</body>

点击图片淡出,点击后自动淡入4张图片

最佳答案

您的代码存在多个问题。尝试将您的工作分割为多个步骤,因为这会更容易让您进步,也让我们更容易帮助您。

这是我试图让它回到正确方向的尝试:

//with proper html class and ids, and multiple instructions in one function, you can greatly reduce the size of your js
$(document).ready(function() {

$(".pulse-button").click(function() {
//BUTTON FADEOUT AND DISABLE
$(this).addClass('fadeOut');
$(this).prop('disabled', true);
//SHOW MAIN CATEGORIE
$("#mainCategorie").fadeToggle("slow", "linear", "complete");

});

$("#mainCategorie img").click(function() {
//HIDE MAIN CATEGORIE
//$("#mainCategorie").fadeOut(300);
//HIDE ALL IMAGES BUT NOT THE ONE CLICKED
//$("#mainCategorie img").not(this).fadeOut(300);
//SHOW KILO SPECIFICATION
$("#kiloSpecification").fadeIn(300);
});

});
/*as for the css simpler is better, first make something working like you want and only after that make it good-looking.*/
/*I removed what was in the way. I'm not using bootstrap so I may have missed some good practice there.*/

* {
margin: 0;
padding: 0;
}

.fadeOut {
opacity: 0;
}

.pulse-button {
transition: all .5s linear;
position: fixed;
width: 200px;
height: 200px;
border: none;
box-shadow: 0 0 0 0 rgba(232, 76, 61, 0.7);
border-radius: 50%;
background-color: #e84c3d;
color: white;
background-size: auto;
background-repeat: no-repeat;
cursor: pointer;
-webkit-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
-moz-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
-ms-animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
animation: pulse 1.25s infinite cubic-bezier(0.66, 0, 0, 1);
position: absolute;
display: inline-block;
top: 50%;
left: 50%;
line-height: 40px;
margin-top: -50px;
margin-left: -50px;
}

.pulse-button:hover {
-webkit-animation: none;
-moz-animation: none;
-ms-animation: none;
animation: none;
}

@-webkit-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@-moz-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@-ms-keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}

@keyframes pulse {
to {
box-shadow: 0 0 0 45px rgba(232, 76, 61, 0);
}
}


/* BACKGROUND */

.hero-image {
background: url(imgs/sajad-mohammadi-1159479-unsplash.jpg) no-repeat center;
background-size: cover;
!important position: relative;
}


/*----------*/

.column {
width: 25%;
display:inline-block;
text-align:center;
}
.column img{
display:inline-block;
width:90%;
height:50px;
}
/*if you want some img to have specific proportions, add them here like so :
#plasterBoard{
width:50px;
height:50px;
}
*/


@media screen and (max-width: 500px) {
.column {
width: 100%;
}
}

.imgBorder {
background-color: white;
box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
-moz-box-shadow: 0 1px 2px rgba(34, 25, 25, 0.4);
-webkit-box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
}
<head>
<!--try to only include scripts you need, including multiple jquery instance could create bugs-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<!--your style and js goes here-->

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>

<body>
<!--in the html, use div to group content as you need it : in your case you need at least a div for the start, a div for the "main category", and a div for the "kilo selection"-->
<!-- START BUTTON -->
<div>
<button id="pulseButton" class="pulse-button" class="container" style="align-content: center; outline: none;">
<h1>START</h1>
</button>
</div>
<!-- END START BUTTON -->

<!-- MAIN CATEGORY SELECTION -->
<div id="mainCategorie" style="display:none;" class="hero-image">
<div class="row">

<div class="column">
<img id="plasterBoard" src="imgs/Plasterboard.jpeg" alt="plasterboard" class="imgBorder">
</div>

<div class="column">
<img id="brick" src="imgs/brick.jpeg" alt="brick" class="imgBorder">
</div>

<div class="column">
<img id="concreteStone" src="imgs/concrete(stone).jpeg" alt="concreteStone" class="imgBorder">
</div>

<div class="column">
<img id="aerateConcrete" src="imgs/aeratedConcrete.jpg" alt="aerateConcrete" class="imgBorder">
</div>

</div>
</div>
<!-- END MAIN CATEGORY SELECTION -->

<!-- KILO SPECIFICATION SELECTION -->
<div id="kiloSpecification" style="display:none;" class="hero-image">
<div class="row">

<div class="column">
<img id="kilosIcon10" src="imgs/10kilo.png" alt="10kilo" class="imgBorder">
</div>

<div class="column">
<img id="kilosIcon20" src="imgs/20kilo.png" alt="20kilo" class="imgBorder">
</div>

<div class="column">
<img id="kilosIcon30" src="imgs/30kilo.png" alt="30kilo" class="imgBorder">
</div>

<div class="column">
<img id="kilosIcon40" src="imgs/40kilo.png" alt="40kilo" class="imgBorder">
</div>

</div>
</div>

</body>

有很多话要说,但我试图将其保持在最低限度,并在代码中显示其余部分。如果您需要我扩展某些内容,请不要犹豫,但请再次尝试逐步进行:您需要学习很多东西,并且您已经在 SO 上回答了很多问题。

作为一个好的经验法则,尝试从 html(“好的,我想要我的页面中有 4 行,每行 4 张图片”)开始,然后是基本的 css(“我希望我的图片并排放置”),然后js(“现在,我希望我的图像仅在单击开始时出现”)并且仅在高级 css 之后(“我想要闪烁和旋转图像!”)。

祝你好运!

关于javascript - 如何在单击时淡出 1 张图片并自动淡入彼此靠近的 4 张图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55532194/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com