【发布时间】:2015-01-30 19:21:51
【问题描述】:
这是我的fiddle 用于视觉理解,它有点乱,但它对我有用。当您单击该框时,它将切换一个带有圆圈的 DIV。我希望那个圆圈像灯一样闪烁。其他框将显示为绿色、黄色和红色的不同颜色。颜色对应于他们的状态,例如登录、在线和离线。我制作这些圈子的方式是通过查看它们的状态来使用 PHP。我正在使用一个名为 $circle 的 canvas 类型的变量,因为我不知道该怎么做。下面是我的代码,我只展示了“圆圈”的一部分。
如果动画无法工作,我使用的是 Internet Explorer 9.08。
提前致谢!
PHP:
$class = ""; //class variable to empty string, the IF statements are below it
$state = ""; //state variable to empty string
//ONLINE
//if ping succeeds but no user is found
if( ($user == null) && ($online == 1) ){
$user = "No User";
$class = "online";
$state = "Online";
}
//LOGGED IN
//ping succeeds and a user is found
elseif( ($user != null) && ($online == 1) ){
//user will be the value from $row['username']
$class = "loggedin";
$state = "Logged In";
}
//OFFLINE
//if No ping make user and class name show offline
else{
$user = "No User";
$class = "offline";
$state = "Offline";
}
//display DIV with the content inside
echo '<div class="station_info_ ' . $class . '" id="station_info_' . $id . ' circle" rel="' . $class . '" style="left:' . $x_pos . 'px;top:' . $y_pos . 'px;"><p>User:' . $user .'<br>Station:' . $hostname . '<br>Pod:' . $sta_num . '<br>Section:' . $sec_name . '<br>State:' . $state .'<br></p></div>' . "\n";
【问题讨论】:
-
你需要 CSS 来做到这一点。不需要用 SBG 来做一个脉动的循环,IMO 有点矫枉过正。
-
@Bonatoc 这就是我需要帮助的原因,我对 CSS 不是很好。我的想象力很糟糕,哈哈
-
您必须在客户端使用 JQuery $ajax,并将上面显示的代码用作 REST 系统。一旦 php 返回该值,您就可以使用 jQuery 和 addClass/removeClass 来定位一个纯 html“圆圈”(一个宽度 = 高度的 div,带有夸张的圆形边框)。给我 5 分钟,我正在研究脉动的 CSS 方面。
-
如果你愿意,你可以使用 html 5 动画标签来让你的形状闪烁,你可以让动画无穷无尽,像这样:stackoverflow.com/questions/11828179/…。另外,也快看看这篇文章,它对我个人帮助很大:css-tricks.com/guide-svg-animations-smil。在任何情况下,您都可以选择使用 javascript 或 css,不过我会使用 CSS,因为 SVG 本身就支持动画。
-
@briosheje 有趣的文章,我会研究一下,谢谢!我知道 SVG 是与 CSS 一起使用的最佳选择。我只需要练习更多的 CSS,我发现它对我来说是最难的。谢谢!
标签: javascript php jquery html css