我正在尝试添加一个链接到另一个的 fadeOut 函数。 CLICK HERE目前我有一个闪烁的标志。当用户点击 Logo 时,闪烁停止,稍有延迟,然后慢慢淡出。有没有人能够纠正我粘贴在下面的代码?
<script>
$(document).ready(function(){
$("#center-gif").click(function(){
$('#center-gif').hide();
$('#center-img').show();
});
$('#center-img').click(function(){
$('#center-img').hide();
$('#center-img-gif').show();
});
$('flash-link').click(function(){
$('center-img').fadeOut(5000);
});
});
</script>
最佳答案
如果你想访问带有class
/id
的元素;你必须始终在开头定义 .
和 #
,就像 css 一样。
一些例子:
$('img').fadeOut();//selects all img elements
$('.img').fadeOut();//selects all elements with class="img"
$('myClass').fadeOut(); //false
$('.myClass').fadeOut(); //true
$('myId').fadeOut(); //false
$('#myId').fadeOut(); //true
这是用更少的代码为您的问题工作的 jQuery:
$(document).ready(function(){
$("img").click(function(){
var takeId = $(this).attr('id');//takes clicked element's id
$('img').hide();//hides all content
$('#'+takeId).show();
//matches clicked element's id with element and shows that
});
$('#flash-link').click(function(){//define '#' id declaration here
$('#center-img').fadeOut(5000,//new function after fadeOut complete
function() {
window.open('url','http://iamnatesmithen.com/jukebox/dancers.php');
return false;
});
);
});
});
关于javascript - jQuery 淡出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11539866/