我这里有问题;
$("#anan").click(function(){
$("input[type='text']").fadeToggle();
});
我希望我的输入框消失并显示淡入淡出效果。目前,它只出现并消失而没有褪色效果。有人可以帮助我为什么它不会淡入/淡出?
注意:在预览中,由于某种原因它甚至不会消失/出现,但是当我在Chrome上实际运行html时,它的功能正常,除了淡化动画。
$("ul").on("click", "li", function() {
$(this).toggleClass("completed");
});
$("ul").on("click", "span", function(event) {
$(this).parent().fadeOut(500, function() {
$(this).remove();
});
event.stopPropagation();
})
$("input[type ='text']").on("keypress", function(event) {
if (event.which === 13) {
var inputtext = $(this).val();
$(this).val("");
$("ul").append("<li><span><i class='fas fa-trash'></i></span> " + inputtext + "</li>")
}
})
$("#anan").click(function() {
$("input[type='text']").fadeToggle();
});
&#13;
h1 {
background: #2980b9;
color: white;
margin: 0;
padding: 10px 20px;
text-transform: uppercase;
font-size: 24px;
font-weight: normal;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.fa-plus {
float: right;
}
body {
background: #ff6e7f;
/* fallback for old browsers */
background: -webkit-linear-gradient(to right, #bfe9ff, #ff6e7f);
/* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #bfe9ff, #ff6e7f);
/* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
font-family: Roboto;
}
li {
background: #fff;
height: 40px;
line-height: 40px;
color: #666;
}
input {
font-size: 18px;
color: #2980b9;
background-color: #f7f7f7;
width: 100%;
box-sizing: border-box;
padding: 13px 13px 13px 20px;
border: 3px solid rgba(0, 0, 0, 0);
}
input:focus {
background: #fff;
border: 3px solid #2980b9;
outline: none;
}
li:nth-child(2n) {
background: #f7f7f7;
}
li span {
background: #e74c3c;
height: 40px;
margin-right: 20px;
text-align: center;
color: white;
width: 0;
display: inline-block;
transition: 0.2s linear;
opacity: 0;
}
li:hover span {
width: 40px;
opacity: 1.0;
}
#container {
width: 360px;
margin: 100px auto;
background: #f7f7f7;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.1);
}
.completed {
color: gray;
text-decoration: line-through;
}
&#13;
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>ToDo List App</title>
<script type="text/javascript" src="assets/js/lib/jquery-3.3.1.min.js">
</script>
<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
</head>
<body>
<div id="container">
<h1>To-Do List <span id="anan"><i class="fas fa-plus"></i></span></h1>
<input type="text">
<ul>
<li><span><i class="fas fa-trash"></i></span> Go to Potions Class</li>
<li><span><i class="fas fa-trash"></i></span> Buy new robes</li>
<li><span><i class="fas fa-trash"></i></span> Visit anan</li>
</ul>
</div>
<script type="text/javascript" src="assets/js/mycustom.js">
</script>
</body>
</html>
&#13;
答案 0 :(得分:0)
您缺少JQuery脚本:
h1 {
background: #2980b9;
color:white;
margin: 0;
padding: 10px 20px;
text-transform: uppercase;
font-size: 24px;
font-weight: normal;
}
ul {
list-style: none;
margin: 0;
padding: 0;
}
.fa-plus{
float:right;
}
body {
background: #ff6e7f; /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #bfe9ff, #ff6e7f); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #bfe9ff, #ff6e7f); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
font-family: Roboto;
}
li {
background: #fff;
height: 40px;
line-height: 40px;
color: #666;
}
input {
font-size: 18px;
color: #2980b9;
background-color: #f7f7f7;
width: 100%;
box-sizing: border-box;
padding: 13px 13px 13px 20px;
border: 3px solid rgba(0,0,0, 0);
}
input:focus{
background: #fff;
border: 3px solid #2980b9;
outline: none;
}
li:nth-child(2n){
background: #f7f7f7;
}
li span {
background: #e74c3c;
height: 40px;
margin-right: 20px;
text-align: center;
color: white;
width: 0;
display: inline-block;
transition: 0.2s linear;
opacity: 0;
}
li:hover span {
width: 40px;
opacity: 1.0;
}
#container {
width: 360px;
margin: 100px auto;
background: #f7f7f7;
box-shadow: 0 0 3px rgba(0,0,0, 0.1);
}
.completed {
color: gray;
text-decoration: line-through;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">
<div id="container">
<h1>To-Do List <span id="anan"><i class="fas fa-plus"></i></span></h1>
<input type="text">
<ul>
<li><span><i class="fas fa-trash"></i></span> Go to Potions Class</li>
<li><span><i class="fas fa-trash"></i></span> Buy new robes</li>
<li><span><i class="fas fa-trash"></i></span> Visit anan</li>
</ul>
</div>
<script type="text/javascript" src="assets/js/mycustom.js">
</script>
{{1}}
{{1}}
答案 1 :(得分:0)
在我们的codepen中你没有包含jquery,在你的css中,文本框背景是#f5f5f5,它与它的背景相同。所以你需要改变文本框的背景颜色才能看到淡入淡出效果。您可以将红色设置为测试示例。在JS中,您需要在fadeToggle
上提及参数$("input[type='text']").fadeToggle("2000", "linear");
这里,2000代表2秒。你可以随意增加。有关更多详细信息,您需要查看http://api.jquery.com/fadetoggle/
上的文档我已在codepen上进行了编辑:https://codepen.io/hirakumar/pen/aKpQNN?editors=0001