gpt4 book ai didi

javascript - 如何制作像 Facebook 通知这样的东西?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:47:35 26 4
gpt4 key购买 nike

请在思考错误之前阅读所有问题。

Implementing a Facebook Notifications like style

我正在尝试实现类似 Facebook 的通知系统,但我需要一些帮助来设计它。我已经发出通知,后端工作完美,但我正在使用样式的解决方法 - 相信我,这很慢,丑陋并且无法为我提供样式源的好方法。

我确切地说的是发生在“用户点击通知”和“用户接收加载的通知”之间的 Action 。我说的是这部分的风格。诸如“我怎样才能打开一个装有通知的盒子?”之类的东西。单击按钮/div/图像/文本后。

好的,让我们继续。现在我正在使用 Fancybox创建我的通知框 - 是的,FANCYBOX!以下是单击“通知”按钮(“0”)后我使用 Fancybox 获得的视觉效果:

My Notification with Fancybox

这对你来说可能看起来很漂亮,但对我来说它很丑——而且这真的非常慢。为了解决这个问题,我禁用了 Fancybox 的图像,所以当它加载时,它加载时没有黑色背景、关闭窗口的“X”和其他东西。以下是我的代码。

部分负责 header :

<!-- This is the html generated by Ruby on Rails,number is dynamic-->
<a href="/notifications/index" class="various fancybox.ajax">0</a>

<script>
$(document).ready(function(){
$(".various").fancybox({
openEffect: 'none',
closeEffect: 'none',
prevEffect: 'none',
nextEffect: 'none',
fitToView : false,
autoSize: false,
scrolling: 'auto',
maxWidth:300,
maxHeight:500,
padding: 0,
leftRatio: 0.86,
topRatio: 0.18
});
});
</script>

这是 notifications/index/生成的 HTML(对于实际示例):

<div class="post group">
<div class="notifications-content">
<div class="group" id="notification-0">
<div class="post-middle">
<div class="notifications-title">
<b>Bruno postou:</b>
</div>
<div class="post-middle-text">
ADO
</div>
<div class="post-middle-actions with-dots">
<label> Postado às 12:34 de 17 de October</label>
</div>
</div>
</div>
</div>

<div class="notifications-content">
<div class="group" id="notification-1">
<div class="post-middle">
<div class="notifications-title">
<b>Fernando Paladini postou:</b>
</div>
<div class="post-middle-text">
hummmmmmmmm #boilo
</div>
<div class="post-middle-actions with-dots">
<label> Postado às 12:36 de 17 de October</label>
</div>
</div>
</div>
</div>

<div class="notifications-content">
<div class="group" id="notification-2">
<div class="post-middle">
<div class="notifications-title">
<b><a href="#">@Ramon Diogo</a> postou:</b>
</div>
<div class="post-middle-text">
http://www.youtube.com/watch?v=A3zPI-DBf7U
</div>
<div class="post-middle-actions with-dots">
<label></label>
<label>Comentado às 12:47 de 17 de October</label>
</div>
</div>
</div>
</div>
</div>

我如何仅使用 HTML、CSS 和 jQuery/JS 来做到这一点?我的意思是,这种效果是单击按钮时打开一个包含加载内容的“框”,而单击关闭时关闭“框”。我真的,真的不知道怎么做。实际上我正在使用 Fancybox 打开一个模式,但我不想打开一个模型,我想让它像 Facebook 和像 Trello 这样的网站那样做——只是 css/jquery。

请注意,我不是在要求代码,我需要帮助,因为我不知道如何做到这一点。我想要说明:单击按钮时我需要做什么,打开通知框。或者当单击外部通知框时,关闭通知框。这背后的概念,但如果您也发布一些代码,我会考虑,因为这将帮助我学习。

最佳答案

您可以通过在包含您的通知的 div 上进行绝对定位来做到这一点。

它应该作为默认行为隐藏,您可以使用 javascript 使其在点击时可见。

这将帮助您:http://net.tutsplus.com/tutorials/html-css-techniques/how-to-create-a-drop-down-nav-menu-with-html5-css3-and-jquery/但是您应该更改行为以对单击事件而不是 mouseenter 使用react(脚本部分的第 14 行)。用类似的东西替换那部分:

$(this).click(function(e) {  
$(this).find("ul").stop(true, true).slideDown();
e.preventDefault();
});

注意“preventDefault部分?就是避免浏览器在你点击的时候进入链接。”

关于javascript - 如何制作像 Facebook 通知这样的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19461449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com