jQuery淡出函数
jQuery FadeOut function
我正在尝试添加一个fadeOut函数,该函数链接到另一个函数。点击这里目前我有一个闪烁的标志。当用户点击徽标时,闪烁停止,略有延迟,然后慢慢淡出。有人能纠正我粘贴在下面的代码吗?
<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;
});
);
});
});
所以我认为你的问题是图像不会淡出,对吧?
这可以解决问题:
首先将您的.click()
-函数更改为:
$().click( function(event) {
// cour code
event.preventDefault();
}
然后改变最后一个:
$('#flash-link').click( function(event) {
$('#center-img').fadeOut( 5000, function() {
window.location.href = 'jukebox/dancers.php';
});
event.preventDefault();
});
我没有测试,但它应该有效。它的作用是:它淡出图像,并在准备好时调用一个函数。此功能然后重定向到您的下一页。
event.preventDefault();
将通知浏览器不要委派click
-事件。如果你不把它放在那里,浏览器会在不等待任何JavaScript执行的情况下打开锚。
备注
如果要选择具有ID的元素,请使用此选择器:$('#[id]')
,因为此选择器$('html')
仅适用于HTML元素。
相关文章:
- jqueryget函数后的淡出
- 如何延迟jQuery函数以等待内容淡出
- jQuery淡出函数
- 如何防止在单击和淡出函数中更改变量的值
- 我可以在淡入/淡出 JQuery 函数中使用 标记按钮类吗?
- 淡出(..).removeClass 不是一个函数
- 在此 JavaScript 函数中显示淡入淡出效果
- 图像淡出到另一个,然后函数加载新的网页
- 为什么我的Jquery淡出函数不能工作?
- jquery中淡出函数的问题
- 向Jquery淡出函数传递参数
- 在淡出后调用函数
- 我如何禁用淡出效果在这个javascript函数
- Dojo淡出只在验证期间的函数调用中工作一次
- 如何添加淡入/淡出效果到我的函数,而不是仅仅设置可见性隐藏/可见
- 如何在没有唯一ID/类的情况下淡出函数
- jQuery BlockUI.在BlockUI淡出后执行一个函数
- JavaScript 淡出函数在第二次调用时不起作用
- 标签上的 JavaScript 淡入淡出函数
- 简单的Javascript CSS不透明度淡入淡出函数