【发布时间】:2013-12-31 19:44:52
【问题描述】:
我想为我的网站制作一个活动日历。在日历上,我想在悬停时在某个日期显示整个 event_description。但我不知道怎么做。我使用 jquery 和 mysqli 进行悬停和检索数据。
这是我当前项目的图像 http://i.stack.imgur.com/xNgZM.jpg
我有一个包含“event_id、event_title、event_date 和 event_description”的数据库
这就是我从数据库中获取价值的方式。
while($r=$q->fetch_assoc()) {
$event_id=$r['event_id']; //This is a unique ID from my DB
$event_title=$r['event_title']; //Obvious title is obvious
$event_desc=$r['event_desc']; // I want to post this on the popbox at the bottom
echo $event_title."<br />";
<a class='popper' data-popbox='pop2' href='viewEvent?id=$event_id'>See more</a><br />";
echo "<div id='pop2' class='popbox'>";
echo " <h2>Event for today!!</h2>";
echo " This text should have the 'event_description'";
echo "</div>";
div ID pop2 和 class popbox 是链接悬停时的代码。这是脚本
$(function() {
var moveLeft = 0;
var moveDown = 0;
$('a.popper').hover(function(e) {
var target = '#' + ($(this).attr('data-popbox'));
$(target).show();
moveLeft = $(this).outerWidth();
moveDown = ($(target).outerHeight() / 2);
}, function() {
var target = '#' + ($(this).attr('data-popbox'));
$(target).hide();
});
$('a.popper').mousemove(function(e) {
var target = '#' + ($(this).attr('data-popbox'));
leftD = e.pageX + parseInt(moveLeft);
maxRight = leftD + $(target).outerWidth();
windowLeft = $(window).width() - 40;
windowRight = 0;
maxLeft = e.pageX - (parseInt(moveLeft) + $(target).outerWidth() + 20);
if(maxRight > windowLeft && maxLeft > windowRight)
{
leftD = maxLeft;
}
topD = e.pageY - parseInt(moveDown);
maxBottom = parseInt(e.pageY + parseInt(moveDown) + 20);
windowBottom = parseInt(parseInt($(document).scrollTop()) + parseInt($(window).height()));
maxTop = topD;
windowTop = parseInt($(document).scrollTop());
if(maxBottom > windowBottom)
{
topD = windowBottom - $(target).outerHeight() - 20;
} else if(maxTop < windowTop){
topD = windowTop + 20;
}
$(target).css('top', topD).css('left', leftD);
});
});
请告诉我你希望看到什么代码来帮助我解决这个问题。在此先感谢 ;)
【问题讨论】:
-
一种简单的方法是在悬停时调用 ajax 并在工具提示中显示检索到的描述,如果事件不是太多,另一种方法是将所有事件按日期存储在 javascript 数组中并在悬停时, 按日期过滤数组
-
嗨! Joachim,我访问过该站点,并且有很多工具提示!我认为我的解决方案将是 AJAX 对吗?但我对 AJAX 调用和与之相关的事情一无所知。
-
嗨米纳斯!这实际上是我的第一选择!我很想使用这种数组方法,但我想我必须假设将有大量事件存储在这个数组中。你觉得数组调用可以处理吗?
-
对于数组方法,仅在日历中加载当前月份的事件,当日历上的月份发生变化时,您可以调用ajax在数组中加载该月的事件