[英]How the write css transition in jquery
我已经写了一个CSS过渡,但是我无法在JQuery中写它。有人可以帮帮我吗。 这是html:
<body class="icons">
<div class="icon-images">
<i class="fa fa-free-code-camp" aria- hidden="true"></i>
</div>
</body>
CSS:
.icons{
background-color:#DF3713;
height:100%;
weight:100%;
}
.icon-images{
background-color:#198493;
margin-top:5%;
margin-left:25%;
margin-right:25%;
//border-radius:;
height:100px;
width:100px;
-webkit-transform: rotate(0deg);
transition: background-color 0.5s ease-in-out,-webkit-transform 0.5s ease-in-out;
}
.icon-images:hover{
background-color:yellow;
transform:rotate(180deg);
}
您想从代码触发悬停事件吗?
$(".icon-images").hover();
请尝试以下操作:
$('.icon-images').hover(function() { $( this ).css('background-color', 'yellow'); $( this ).css('transform', 'rotate(180deg)'); $( this ).css('transition', 'background-color 0.5s ease-in-out,-webkit-transform 0.5s ease-in-out'); }, function() { $( this ).css('background-color', '#198493'); $( this ).css('transform', 'rotate(0deg)'); } );
.icons{ background-color:#DF3713; height:100%; weight:100%; } .icon-images{ background-color:#198493; margin-top:5%; margin-left:25%; margin-right:25%; //border-radius:; height:100px; width:100px; -webkit-transform: rotate(0deg); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="icon-images"> <i class="fa fa-free-code-camp" aria- hidden="true"></i> </div>
我检查了您的链接,唯一的问题是您的JS没有引用jQuery库。 要在Codepen上执行此操作,请单击“ JS”旁边的“齿轮”按钮,然后在叠加菜单中从“快速添加”中选择“ Jquery”。
因此,基本上,即使您编写的所有jQuery都是正确的,它也没有运行,因为HTML文档中未引用jQuery源。
这是您问题的有效解决方案。
[Fiddle Solution][1]
探索jQuery函数以添加类似的onfocusout事件,以将其旋转回其正常形式。
我希望这对你有用.. !!
$(document).ready(function(){ $('.icon-images').hover(function(){ $(this).css({'background-color':'yellow','transform':'rotate(130deg)'}); },function(){$(this).css({'background-color':'#198493','transform':'rotate(0)'})}); });
.icon-images{ background-color:#198493; margin-top:5%; margin-left:25%; margin-right:25%; height:100px; width:100px; -webkit-transform: rotate(0deg); transform:rotate(0deg); transition: background-color 0.5s ease-in-out,-webkit-transform 0.5s ease-in-out; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <div class="icon-images"> <i class="fa fa-free-code-camp" aria-hidden="true"></i> </div>
要使用jQuery设置过渡,请尝试以下操作:
$(document).ready(function(){
$(".icon-images").css({
transition : 'background-color 0.5s ease-in-out,-webkit-transform 0.5s ease-in-out'
});
});
查看小提琴: https : //jsfiddle.net/NayanaDas/hur66rc6/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.