【发布时间】:2016-07-12 14:42:09
【问题描述】:
我想在输入焦点上停止 span 的动画。
当我做悬停时,没有问题,总是好的。但是当我关注输入时,我想停止跨度。问题就在这里。我的代码是here。
实际上我想用css而不是scss来做这个。 here
还有HTML:
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300' rel='stylesheet' type='text/css'>
<section id="text">
<p><span> İSİM</span><input name="name" type="text" placeholder="İsminiz" /></p>
<p><span> KONU </span><input name="subject" type="text" placeholder="Konu"/></p>
<p><span> MAİL </span><input name="mail" type="email" placeholder="Mailiniz"/></p>
<p><span> MESAJ </span><textarea name="message" type="text" placeholder="Mesajınız"></textarea>
</section>
CSS:
.aktif1{width:100px;transition:1s;}
.aktif2{width:450px;transition:1s;}
body{
background:#f7f7f7;
}
p{
position: relative;
width:450px;
}
section#text{
position:relative;
margin-left:500px;
margin-top:150px;
}
p input{
outline:none;
width:330px;
height:40px;
padding-left:120px;
}
p textarea{
outline:none;
max-width:330px;
max-height:40px;
width:330px;
height:40px;
padding-left:120px;
}
p span{
width:455px;
height:45px;
background:#333;
position: absolute;
color:white;
text-align:center;
line-height:50px;
font-family: 'Open Sans', sans-serif;
font-weight:bold;
transition:1s;
}
jquery:
$(function() {
fonk1();
$('section#text input').focus(function(){
fonk1().stop();
});
fonk2();
$('section#text input').blur(function(){
fonk2();
});
});
var fonk1 = function(){
$('section#text p').mouseenter(function(){
$('span',this).animate(1000,function(){
$(this).css({'width':'100'});
});
});
}
var fonk2 = function(){
$('section#text p').mouseleave(function(){
$('span',this).animate(1000,function(){
$(this).css({'width':'450'});
});
});
}
【问题讨论】:
-
如果您希望第一个 codepen 使用相同的代码,只需 查看已编译的 CSS ...在 css 窗口上单击向下箭头并选择查看已编译的 CSS。然后你可以看到它是纯 CSS
-
谢谢 我不知道这个功能。但我只是想知道我的代码哪里出错了。
-
您想“在用户聚焦输入后立即停止动画”吗?你的意思是“停止跨度”/“停止悬停”吗?
-
是的,我试着这么说。
-
你混合了 css 动画和 jquery 动画,也许这是你的问题的一部分?你应该像 $('span',this).finish(); 这样调用 .stop() 或 .finish(),而不是不返回任何内容的 fonk 函数的结果:-)