gpt4 book ai didi

javascript - 使用 jquery 创建两个图像的动画

转载 作者:行者123 更新时间:2023-11-30 11:30:53 26 4
gpt4 key购买 nike

我有两张图片需要制作动画。代码在 Stack Overflow 上得到了改进,但它仍然对我不起作用。我不知道我的 CSS 和 html 代码有什么问题。

这是我的代码:

$(document).ready(function() {
$(".animar").click(function() {
$("#img4").addClass("uno");
});
});
#img4 {
width: 7%;
height: auto;
margin: auto;
display: block;
background-size:20%;
float: left;
}

#img5 {
width: 3%;
height: auto;
margin: auto;
display: block;
background-size:20%;
position: relative;
right:20%;
}

.animar {
width: 123px;
height: auto;
margin-right: 15%;
display: block;
background-size:0%;
float:right;
border-color: white;
background-color: rgba(43,86,162, 1.00);
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size: 20px;
color: white;
border-radius: 12px;
border-width: 10px;
}

uno {
animation-name: uno;
animation-duration: 10s;
}

@keyframes uno {
20% {left:80px;}
50%{left:190px;}
70%{left:220px}
100%{left:350px;}
}

#gradiente2 {
background: rgba(43,86,162, 1.00);
position: relative;
margin-bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div class="col-md-12" id="gradiente2">

<p id="t1" class="typewrite" data-period="2000" data-type='[ "En nuestra institución siempre nos preocupamos por brindarte lo mejor" ]'><span class="wrap"></span> </p>

<p id="t2" class="typewrite" data-period="2000" data-type='[ "Síempre le Ponemos Corazón, a lo que hacemos" ]'><span class="wrap"></span> </p>

<div>
<img src="imagenes/kangura.png" class="img-responsive" id="img4">
<img src="imagenes/corazon.png" class="img-responsive" id="img5">
<button class="animar">Entregar Corazón</button>
</div>

</div>

最佳答案

  • 在您的 css 中,您忘记将 . 添加到 uno.uno
  • #img4 中你忘记添加 position:relative

$(document).ready(function() {
$(".animar").click(function() {
$("#img4").addClass("uno");
});
});
#img4 {
position: relative;
width: 7%;
height: auto;
margin: auto;
display: block;
background-size: 20%;
float: left;
}

#img5 {
width: 3%;
height: auto;
margin: auto;
display: block;
background-size: 20%;
position: relative;
right: 20%;
}

.animar {
width: 123px;
height: auto;
margin-right: 15%;
display: block;
background-size: 0%;
float: right;
border-color: white;
background-color: rgba(43, 86, 162, 1.00);
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
font-size: 20px;
color: white;
border-radius: 12px;
border-width: 10px;
}

.uno {
animation-name: uno;
animation-duration: 10s;
}

@keyframes uno {
20% {
left: 80px;
}
50% {
left: 190px;
}
70% {
left: 220px
}
100% {
left: 350px;
}
}

#gradiente2 {
background: rgba(43, 86, 162, 1.00);
position: relative;
margin-bottom: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="col-md-12" id="gradiente2">

<p id="t1" class="typewrite" data-period="2000" data-type='[ "En nuestra institución siempre nos preocupamos por brindarte lo mejor" ]'><span class="wrap"></span> </p>

<p id="t2" class="typewrite" data-period="2000" data-type='[ "Síempre le Ponemos Corazón, a lo que hacemos" ]'><span class="wrap"></span> </p>

<div>
<img src="https://1.img-dpreview.com/files/p/TS1200x900~sample_galleries/7214830437/4039259235.jpg" class="img-responsive" id="img4">

<img src="https://2.img-dpreview.com/files/p/TS1200x900~sample_galleries/7214830437/8857557974.jpg" class="img-responsive" id="img5">
<button class="animar">Entregar Corazón</button>
</div>

</div>

关于javascript - 使用 jquery 创建两个图像的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46269170/

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