onmouseout在交换文本时出错
Error with onmouseout in exchanging text
我有一个链接,在那里我使用Javascript动画文本的变化。我想创建的行为如下
1)用户将鼠标悬停在文本上,一个不同的文本淡入2)当用户移动光标时,文本恢复正常。
我已经设法通过查看另一个代码来创建文本的变化,但是我遇到了麻烦,所以当光标离开链接时,文本会变回来。
你可以看看这里的jsfiddle ->
http://jsfiddle.net/3WMyQ/我得到错误
Uncaught TypeError: Object [object Object] has no method 'onmouseout'
这是html ->
<a href="#" id="stepan_says">
<span>The way you get what you want out of life is...</span>
</a>
JS ->
$("#stepan_says").hover(function(){
$(this).find("span").animate({opacity:0},function(){
$(this).text("I have no idea! But here's the philosophy!")
.animate({opacity:1});
})
$(this).onmouseout(function(){
$(this).find("span").animate({opacity:0},function(){
$(this).text("This is the third text!")
.animate({opacity:1});
})
});
});
帮助非常感谢!:)
使用hover
的回调函数代替mouseleave
。你不需要另一个活动。鼠标悬停的回调将完全按照你的要求进行。
$("#stepan_says").hover(function(){
$(this).find("span").animate({opacity:0},function(){
$(this).text("I have no idea! But here's the philosophy!")
.animate({opacity:1});
})
},function(){
$(this).find("span").animate({opacity:0},function(){
$(this).text("This is the third text!")
.animate({opacity:1});
})
});
演示没有onmouseout
在jQuery中,这是一个本地事件,尝试:
$(this).on('mouseout', function(){
// do stuff
});
然而,hover()
已经为mouseenter和mouseleave都有回调,所以使用它们:
$("#stepan_says").hover(function () {
$(this).find("span").animate({ opacity: 0 }, function () {
$(this).text("I have no idea! But here's the philosophy!")
.animate({ opacity: 1 });
});
},function () {
$(this).find("span").animate({ opacity: 0 }, function () {
$(this).text("This is the third text!")
.animate({ opacity: 1 });
});
});
没有这样的方法onmouseout
试
$(this).mouseleave(function(){
$(this).find("span").animate({opacity:0},function(){
$(this).text("This is the third text!")
.animate({opacity:1});
})
});
小提琴
既然你使用的是悬停,那么你可以像
$("#stepan_says").hover(function(){
$(this).find("span").stop().animate({opacity:0},function(){
$(this).text("I have no idea! But here's the philosophy!").animate({opacity:1});
});
}, function(){
$(this).find("span").stop().animate({opacity:0},function(){
$(this).text("This is the third text!").animate({opacity:1});
});
});
结构为
$("selector").hover(function(){ // on mouse over
}, function(){ // on mouse out
});
相关文章:
- 如何使用jquery在填充自动完成的值后使文本框只读
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 用程序搜索JQuery数据表中的文本
- jQuery匹配JSON对象的部分文本
- onkeyup无法动态创建多个文本区域
- 如何在下面的ES6循环中获得前面的文本
- JavaScript InvalidCharacterError 在编写文本框脚本时出错
- 尝试从ajax静态WebMethod获取asp.net(C#)文本框文本时出错
- 使用在 jquery 和按钮中生成的文本区域时出错
- 获取由使用 webkitbrowser 注入的 JavaScript 修改的输入文本的值时出错
- 获取用户所选文本的 html 时出错
- Reddit Api尝试通过snoocore node.js获取Reddit自文本时出错
- jquery validate和ajax post表单的验证表单空白文本区域出错
- 处理XMLHTTP请求文本响应时出错
- 当试图更新mysql中的表时,禁用的文本框会导致PHP页面出错
- 将值从数组传递到文本框时出错
- onmouseout在交换文本时出错
- 使用JS将二进制数字转换为ASCII文本时出错
- MissingKeyMapError:在本地主机上使用谷歌地图自动完成文本框时出错