鼠标悬停功能获胜'不起作用
Mouseover function won't work
我使用的是Raphael图形和动画,这是一个javascript库。我希望用户将鼠标悬停在底部一行、中间一列的蓝色正方形上。当他们鼠标悬停时,我希望蓝色的盒子发出黑色的光(拉斐尔函数)。我试图在rec8上使用这个函数,但我认为我做得不对。有人能纠正我的代码或帮助我吗?谢谢。:)长命百岁。
<html>
<head><title></title>
<script src="raphael-min.js"></script>
<script src="jquery-1.7.2.js"></script>
<style type="text/css">
#input
{
margin-top:-200px;
}
</style>
</head>
<body>
<div id="draw-here-raphael" style="height: 400px; width: 400px; background: #666; z-index:0;">
</div>
<div id="input" style="z-index:99;" >
<input type="text" value="0"; style="text-align:right;" /><br />
</form>
</div>
<script type="text/javascript">
//all your javascript goes here
$(function() {
var r = new Raphael("draw-here-raphael"),
// Store where the box is
position = 'left',
// Make our pink rectangle
rec = r.rect(20, 20, 250, 300, 10).attr({"fill": "#fbb"});
$("rect").mouseover(function(e) {
$(this).attr({"fill": "red"});
});
$("rect").mouseout(function(e) {
$(this).attr({"fill": "#fbb"});
});
//first column
rec2 = r.rect(30, 80, 50, 40, 5).attr({"fill": "blue"});
rec3 = r.rect(30, 130, 50, 40, 5).attr({"fill": "blue"});
rec4 = r.rect(30, 180, 50, 40, 5).attr({"fill": "blue"});
rec5 = r.rect(30, 240, 50, 40, 5).attr({"fill": "blue"});
//second column
rec6 = r.rect(90, 80, 50, 40, 5).attr({"fill": "blue"});
rec2 = r.rect(90, 130, 50, 40, 5).attr({"fill": "blue"});
rec7 = r.rect(90, 180, 50, 40, 5).attr({"fill": "blue"});
rec8 = r.rect(90, 240, 50, 40, 5).attr({"fill": "blue"});
$("rec8").mouseover(function(e) {
$(this).glow({width:10});
});
$("rec8").mouseout(function(e) {
$(this).glow({width:0});
});
//third column
rec9 = r.rect(150, 80, 50, 40, 5).attr({"fill": "blue"});
rec10 = r.rect(150, 130, 50, 40, 5).attr({"fill": "blue"});
rec11 = r.rect(150, 180, 50, 40, 5).attr({"fill": "blue"});
rec12 = r.rect(150, 240, 50, 40, 5).attr({"fill": "blue"});
});
</script>
</body>
</html>
此选择器:
$("rec8")
是用于任何<rec8 />
标记的jQuery选择器。这些可能并不存在。您应该将鼠标事件附加到返回的拉斐尔元素:
rec8 = r.rect(90, 240, 50, 40, 5).attr({"fill": "blue"});
rec8.mouseover(function(e) {
this.glow({width:10});
});
rec8.mouseout(function(e) {
this.glow({width:0});
});
但出于某种原因,当我鼠标悬停时,并没有消失
这是因为glow
返回了一个表示辉光的新集合,所以您需要将其删除
注意:"辉光"未连接到元素。如果更改元素属性,它将不会自行调整。
你需要跟踪Raphael作为辉光的一部分给你的返回的set
,并将其移除
var rec8 = r.rect(90, 240, 50, 40, 5).attr({"fill": "blue"});
var rect8glow;
rec8.mouseover(function(e) {
rect8glow = this.glow({width:10});
});
rec8.mouseout(function(e) {
rect8glow.remove();
});
你可以在这里看到一个工作演示。
查看此fiddle以获得实时解决方案:http://jsfiddle.net/zhj2r/3/
正如vcsjones所说,您将jquery和raphael组合在一起,但它们并不相关
通过$(this)
,您将raphael对象包装在jquery函数调用中,这是错误的,并且$('rec4')
不是有效的jquery选择器
此外,glow
函数返回一组svg路径,这些路径显示目标对象的接触,因此通过调用glow({width : 0})
,您不是在修改实际辉光的宽度,而是生成另一个宽度为0的辉光元素。
以下是我为使您的代码工作而修改的内容:
rec.mouseover(function(e) {
this.attr({"fill": "red"});
});
rec.mouseout(function(e) {
this.attr({"fill": "#fbb"});
});
// ...
rec8.mouseover(function(e) {
// keep a reference to the glow object so you can remove it later
this.theGlow = this.glow({width:10});
});
rec8.mouseout(function(e) {
this.theGlow.remove();
});
相关文章:
- PhoneGap读写文件获胜'不起作用
- Jquery事件绑定获胜'当作为方法调用时不起作用,但当直接在控制台中调用时会起作用
- webpack-request(jquery)获胜'不起作用
- colorbox与元素实时绑定'分组获胜'不起作用
- jQuery验证插件停止表单提交,提交按钮获胜'不起作用
- 鼠标悬停功能获胜'不起作用
- Cucumber JS超时获胜'不起作用
- UIWebView调用带有参数的JS获胜'不起作用
- jquery id匹配但获胜'根本不起作用
- JQuery animate获胜'不起作用
- 用JavaScript更改按钮的背景颜色获胜'不起作用
- JQuery方法获胜'分配给这个变量后不起作用
- 骨干视图委派事件获胜'不起作用
- Jquery.show按钮获胜'不起作用
- HTML到嵌入式Flash-ExternalInterface回调获胜'不起作用
- Javascript:外部函数获胜'不起作用
- Javascript if子句获胜'不起作用
- 我的Jquery代码仍然获胜'不起作用,但firebug什么也没表现出来
- jQuery AJAX POST to Rails 3.2.1 Params获胜'不起作用
- html页面中的Java脚本获胜'不起作用,但它在drupal页面上确实起作用