2012-06-23 74 views
1

我使用的名片,并用下面的代码工作完美:悬停卡与悬停功能无法正常工作。有任何想法吗?

$.getJSON("userjson.php" 
    function(result){ 
     $('.user').hovercard({ 
      showCustomCard: true, 
      customCardJSON: result, 
      openOnLeft: true 
     }); 
    }); 

在上面的代码我只是考虑存储在当前登录使用的cookies的用户的数据库中的信息:

$username = $_COOKIE['username']; 

$user_select = mysql_query("SELECT * FROM users WHERE username='$username'",$con); 
$user_array = mysql_fetch_array($user_select); 

$user = array(
    'name' => "<p style=\"text-align:left; text-decoration:underline;\">".$user_array['username']."</p>", 
    'bio' => "<p style=\"text-align:left\"><br>".$user_array['bio']."</p>", 
    'image' => "/pictures/users/".$user_array['propic'] 
); 

echo json_encode($user); 

但是,我想,以取代从当前登录的用户信息,用户谁的名字正在上空盘旋用户:

$('.user').hover(function() { 
    var obj = $(this); 
$.getJSON("userjson.php",{name: obj.text()}, 
     function(result){ 
      obj.hovercard({ 
       showCustomCard: true, 
       customCardJSON: result, 
       openOnLeft: true 
      }); 
    }); 
}); 

这确实有效(在某种程度上)。我必须将鼠标悬停在名称上,然后再次显示,然后当我将鼠标移开时它不会消失。

这是我拍摄的2个视频,以便您实际了解什么是什么我说的是:

工作代码同时登录的用户:http://www.youtube.com/watch?v=FrWmOE-r8AA

不工作密码采取悬停用户名:http://www.youtube.com/watch?v=E9ksekpBnv0

我需要帮助!

回答

0

悬停卡不应该在悬停时添加,但最初。

$.each($(".user"), function() { 
    var element = $(this); 
    $.getJSON("userjson.php", {name: $(element).text()}, function(resp) { 
     $(element).hovercard({ 
      showCustomCard: true, 
      customCardJSON: resp, 
      openOnLeft: true 
     }); 
    }); 
}); 
+0

它不再响应所有的悬停卡效应 –

+0

你是否等过JSON加载?在悬停之前确认悬停卡已激活。 – matt3141

+0

即时通讯不太确定我是如何做到这一点的。 –