var hide = false;
$(".list_rowtext").hover(function () {
if (hide) clearTimeout(hide);
$(this).children("img").fadeIn();
},
function () {
hide = setTimeout(function ()
{ $(this).children("img").fadeOut("slow") }, 250);
});
.list_rowtext
is a div tag. Actually what I want is that when I hover on div, image displays and when mouse focus removed then image disappears and this div tag is inside listview itemtemplate
, means its repeating.
It is displaying image when I hover mouse o开发者_StackOverflow中文版n div but image didn't disappear when mouse focus is removed from that div.
A setTimeout-function is always executed in global scope, so this is window when the function gets executed.
Use a closure to point at the desired target:
$(".list_rowtext").hover(
function () {
if (hide) clearTimeout(hide);
$(this).children("img").fadeIn();
},
function () {
var obj=this; //closure
hide = setTimeout(function ()
{ $(obj).children("img").fadeOut("slow"); }, 250);
}
);
精彩评论