tal_gi
3 May 2007, 7:21 PM
Hello,
Quite new to Ext so this may be obvious but couldn't find answer in the forum.
I have a list of items (divs) that are contained in a container. I want to highlight an item once the mouse is over it (mouseover event) and remove the highlight when the mouse
is out (mouseout event). This all works fine using Ext.Element.on(...). The problem is that using this method the event is called also from child elements so if a div contains child divs once the mouse is over a child div we get mouseout event from the parent div which removes the highlight (which is wrong). Is there a way to prevent this behavior ?
Here is the full code, once mousing over the second element (id = 1) this behavior is observed.:-/
<html>
<head>
<link rel="stylesheet" type="text/css" href="js/ext-1.0/resources/css/ext-all.css"/>
<style type="text/css">
.gmt-vis {
margin: 5px 0px 0px 5px; /*top right bottom left*/
padding: 2px;
}
.gmt-child {
margin: 0px 0px 0px 0px; /*top right bottom left*/
padding: 2px;
}
.gmt-back {
background-color:#CCC;
}
.gmt-container {
height:500px;
width: 550px;
overflow-y:auto;
border:1px solid black;
margin:10px;
}
</style>
<script type="text/javascript" src="js/ext-1.0/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="js/ext-1.0/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="js/ext-1.0/ext-all-debug.js"></script>
<script type="text/javascript">
Ext.namespace("gov.gmt");
gov.gmt.VisabilityTest = {
init : function() {
var content = [ "First", "Hidden", "Second" ];
var html = '<div id="{id}" class="{cls}">{body}</div>';
var tpl = new Ext.DomHelper.Template(html);
var containerEl = Ext.get('container');
tpl.compile();
for (var i=0; i<content.length;i++) {
tpl.append(containerEl,{
id: i,
cls: 'gmt-vis',
body: content[i]
});
var elT = Ext.get(i.toString());
if (i === 1) {
tpl.append(elT,{
id: content.length,
cls: 'gmt-child',
body: 'child'
});
}
elT.on("mouseover",this.onMouseOver,this,{stopEvent: true});
elT.on("mouseout",this.onMouseOut,this,{stopEvent: true});
}
},
onMouseOver : function (event,target) {
var el= Ext.get(target.id.toString());
el.addClass('gmt-back');
},
onMouseOut : function (event,target) {
var el= Ext.get(target.id.toString());
el.removeClass('gmt-back');
}
};
Ext.EventManager.onDocumentReady(gov.gmt.VisabilityTest.init, gov.gmt.VisabilityTest, true);
</script>
</head>
<body>
<div id="container" class="gmt-container"></div>
</body>
</html>
Quite new to Ext so this may be obvious but couldn't find answer in the forum.
I have a list of items (divs) that are contained in a container. I want to highlight an item once the mouse is over it (mouseover event) and remove the highlight when the mouse
is out (mouseout event). This all works fine using Ext.Element.on(...). The problem is that using this method the event is called also from child elements so if a div contains child divs once the mouse is over a child div we get mouseout event from the parent div which removes the highlight (which is wrong). Is there a way to prevent this behavior ?
Here is the full code, once mousing over the second element (id = 1) this behavior is observed.:-/
<html>
<head>
<link rel="stylesheet" type="text/css" href="js/ext-1.0/resources/css/ext-all.css"/>
<style type="text/css">
.gmt-vis {
margin: 5px 0px 0px 5px; /*top right bottom left*/
padding: 2px;
}
.gmt-child {
margin: 0px 0px 0px 0px; /*top right bottom left*/
padding: 2px;
}
.gmt-back {
background-color:#CCC;
}
.gmt-container {
height:500px;
width: 550px;
overflow-y:auto;
border:1px solid black;
margin:10px;
}
</style>
<script type="text/javascript" src="js/ext-1.0/adapter/yui/yui-utilities.js"></script>
<script type="text/javascript" src="js/ext-1.0/adapter/yui/ext-yui-adapter.js"></script>
<script type="text/javascript" src="js/ext-1.0/ext-all-debug.js"></script>
<script type="text/javascript">
Ext.namespace("gov.gmt");
gov.gmt.VisabilityTest = {
init : function() {
var content = [ "First", "Hidden", "Second" ];
var html = '<div id="{id}" class="{cls}">{body}</div>';
var tpl = new Ext.DomHelper.Template(html);
var containerEl = Ext.get('container');
tpl.compile();
for (var i=0; i<content.length;i++) {
tpl.append(containerEl,{
id: i,
cls: 'gmt-vis',
body: content[i]
});
var elT = Ext.get(i.toString());
if (i === 1) {
tpl.append(elT,{
id: content.length,
cls: 'gmt-child',
body: 'child'
});
}
elT.on("mouseover",this.onMouseOver,this,{stopEvent: true});
elT.on("mouseout",this.onMouseOut,this,{stopEvent: true});
}
},
onMouseOver : function (event,target) {
var el= Ext.get(target.id.toString());
el.addClass('gmt-back');
},
onMouseOut : function (event,target) {
var el= Ext.get(target.id.toString());
el.removeClass('gmt-back');
}
};
Ext.EventManager.onDocumentReady(gov.gmt.VisabilityTest.init, gov.gmt.VisabilityTest, true);
</script>
</head>
<body>
<div id="container" class="gmt-container"></div>
</body>
</html>