[英]Hiding a DIV by click on another DIV
I have a 'div' tag( by id=go) and write a script which i click on div, then another div (by id=example) will be shown, and show some data: this is my div : 我有一个'div'标签(通过id = go)并编写一个脚本,单击div,然后将显示另一个div(通过id = example),并显示一些数据:这是我的div:
<div id="go" style="position: relative">Click</div>
<div id="example" style="position: relative"></div>
and the script: 和脚本:
$("#go").click(function () {
$("#example").fadeIn(1200);
$("#count").text('');
setInterval(
function () {
p(); count();
}, 8000);
});
and i want when i click on div(by id= go) agin the div (with id=example) be hide , How can i improve my script to do it? 并且我想当我单击div(by id = go)时div(id = example)被hide,我该如何改善我的脚本来做到这一点?
You can use fadeToggle() to toggle between fadeIn()
and fadeOut()
here: 您可以在这里使用fadeToggle()在fadeIn()
和fadeOut()
之间切换:
$("#example").fadeToggle(1200);
Did you try .toggle()
? 您尝试过.toggle()
吗? Reference is at jQuery docs . 参考在jQuery docs上 。 AFAIK it does all you need - including animation. AFAIK可满足您的所有需求-包括动画。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.