【转】 jquery实现登录后右下角弹窗提醒(附带简单样式)

最近需要实现一个登陆后页面右下角弹出提示层的功能,便找了一些素材,并再次记录一下。效果图:

页面代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>jQuery实现网页右下角悬浮层提示</title>
        <style type="text/css">
            *{margin:0;padding:0;list-style-type:none;}
            a,img{border:0;}
            body{font:12px/180% Arial, Helvetica, sans-serif, "新宋体";}

            /* pop */
            #pop{background:#fff;width:260px;border:1px solid #e0e0e0;font-size:12px;position:fixed;right:10px;bottom:10px;}
            #popHead{line-height:32px;background:#f6f0f3;border-bottom:1px solid #e0e0e0;position:relative;font-size:12px;padding:0 0 0 10px;}
            #popHead h2{font-size:14px;color:#666;line-height:32px;height:32px;}
            #popHead #popClose{position:absolute;right:10px;top:1px;}
            #popHead a#popClose:hover{color:#f00;cursor:pointer;}
            #popContent{padding:5px 10px;}
            #popTitle a{line-height:24px;font-size:14px;font-family:'微软雅黑';color:#333;font-weight:bold;text-decoration:none;}
            #popTitle a:hover{color:#f60;}
            #popIntro{text-indent:24px;line-height:160%;margin:5px 0;color:#666;}
            #popMore{text-align:right;border-top:1px dotted #ccc;line-height:24px;margin:8px 0 0 0;}
            #popMore a{color:#f60;}
            #popMore a:hover{color:#f00;}
        </style>
    </head>
    <body style="height:1200px;" οnlοad="loadhtml();">
        <script  type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
        <script type="text/javascript">
            (function($j){
                $j.positionFixed = function(el){
                    $j(el).each(function(){
                        new fixed(this)
                    })
                    return el;                  
                }
                $j.fn.positionFixed = function(){
                    return $j.positionFixed(this)
                }
                var fixed = $j.positionFixed.impl = function(el){
                    var o=this;
                    o.sts={
                        target : $j(el).css('position','fixed'),
                        container : $j(window)
                    }
                    o.sts.currentCss = {
                        top : o.sts.target.css('top'),              
                        right : o.sts.target.css('right'),              
                        bottom : o.sts.target.css('bottom'),                
                        left : o.sts.target.css('left')             
                    }
                    if(!o.ie6)return;
                    o.bindEvent();
                }
                $j.extend(fixed.prototype,{
                    ie6 : $.browser.msie && $.browser.version < 7.0,
                    bindEvent : function(){
                        var o=this;
                        o.sts.target.css('position','absolute')
                        o.overRelative().initBasePos();
                        o.sts.target.css(o.sts.basePos)
                        o.sts.container.scroll(o.scrollEvent()).resize(o.resizeEvent());
                        o.setPos();
                    },
                    overRelative : function(){
                        var o=this;
                        var relative = o.sts.target.parents().filter(function(){
                            if($j(this).css('position')=='relative')return this;
                        })
                        if(relative.size()>0)relative.after(o.sts.target)
                        return o;
                    },
                    initBasePos : function(){
                        var o=this;
                        o.sts.basePos = {
                            top: o.sts.target.offset().top - (o.sts.currentCss.top=='auto'?o.sts.container.scrollTop():0),
                            left: o.sts.target.offset().left - (o.sts.currentCss.left=='auto'?o.sts.container.scrollLeft():0)
                        }
                        return o;
                    },
                    setPos : function(){
                        var o=this;
                        o.sts.target.css({
                            top: o.sts.container.scrollTop() + o.sts.basePos.top,
                            left: o.sts.container.scrollLeft() + o.sts.basePos.left
                        })
                    },
                    scrollEvent : function(){
                        var o=this;
                        return function(){
                            o.setPos();
                        }
                    },
                    resizeEvent : function(){
                        var o=this;
                        return function(){
                            setTimeout(function(){
                                o.sts.target.css(o.sts.currentCss)      
                                o.initBasePos();
                                o.setPos()
                            },1)    
                        }           
                    }
                })
            })(jQuery)
            function Pop(title,url,intro){
                this.title=title;
                this.url=url;
                this.intro=intro;
                this.apearTime=1000;
                this.hideTime=500;
                this.delay=10000;
                //添加信息
                this.addInfo();
                //显示
                this.showDiv();
                //关闭
              this.closeDiv();
            }
            Pop.prototype={
              addInfo:function(){
                $("#popTitle a").attr('href',this.url).html(this.title);
                $("#popIntro").html(this.intro);
                $("#popMore a").attr('href',this.url);
              },
              showDiv:function(time){
                    if (!($.browser.msie && ($.browser.version == "6.0") && !$.support.style)) {
                  $('#pop').slideDown(this.apearTime).delay(this.delay).fadeOut(400);;
                } else{//调用jquery.fixed.js,解决ie6不能用fixed
                  $('#pop').show();
                        jQuery(function($j){
                            $j('#pop').positionFixed()
                        })
                }
              },
              closeDiv:function(){
                $("#popClose").click(function(){
                      $('#pop').hide();
                    }
                );
              }
            }
        </script>
        <script type="text/javascript" >
        //页面加载调用
        window.οnlοad=function(){
            //使用参数:1.标题,2.链接地址,3.内容简介
            new Pop("HELLO!",
                "https://blog.csdn.net/wqlinloveruby",
                "此处填写提示内容!");
        }
        </script>
        <div id="pop" style="display:none;">
            <div id="popHead"> <a id="popClose" title="关闭">关闭</a>
                <h2>温馨提示</h2>
            </div>
            <div id="popContent">
                <dl>
                    <dt id="popTitle"></dt>
                    <dd id="popIntro"></dd>
                </dl>
				<p id="popMore"><a href="https://blog.csdn.net/wqlinloveruby" target="_blank">查看 »</a></p>
            </div>
        </div>
        <div style="text-align:center;clear:both">
        <p>jquery 右下角弹窗提示</p>
        <p><a href="https://blog.csdn.net/wqlinloveruby" target="_blank">欢迎关注</a></p>
        </div>
    </body>
</html>


                
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要实现类似于美团的下角,可以借助jQuery的推送消息功能来完成。具体步骤如下: 首先,需要在页面里引入jQuery的库文件。 其次,编写相应的html、css和js代码,实现样式和内容。可以在页面上任意位置添加一个隐藏的div元素,用来存储的具体内容和样式。比如: ```html <div id="push-message" style="display:none"> <div class="push-message-header"> <span class="push-message-title">新品上线啦!</span> <a class="push-message-close">×</a> </div> <div class="push-message-body"> <img src="new-product.png" alt="新品图片"> <p>快来抢购新品,先到先得!</p> </div> </div> ``` 然后,在js代码中,使用jQuery的animate()方法来实现动画效果,并调用setTimeout()方法来控制的显示时间和关闭按钮的点击事件。代码示例如下: ```javascript $(document).ready(function(){ // 显示动画效果 $("#push-message").animate({bottom:"20px"}, 1000); // 自动隐藏 setTimeout(function(){ $("#push-message").fadeOut(); }, 5000); // 关闭按钮点击事件 $(".push-message-close").click(function(){ $("#push-message").fadeOut(); }); }); ``` 最后,需要在页面中调用该js文件,使能够正常显示和关闭。 总体来说,实现类似于美团的下角并不难,只需要按照上述步骤进行相应的设置和调整即可。 ### 回答2: 实现类似于美团的下角,可以使用jQuery推送消息的方法。 具体实现步骤如下: 1.在页面底部引入jQuery库文件。 2.定义一个DIV标签作为容器,设置其样式为固定定位,底部距离为0,侧距离为0,宽度和高度自定义大小。 3.编写jQuery代码,实现出和隐藏: a)当页面加载完成时,设置容器的初始位置为底部侧隐藏状态; b)当触发某个事件时(如点击按钮事件),在容器中添加需要显示的内容,并将容器位置从底部侧滑动到底部左侧显示状态; c)当点击容器的关闭按钮时,将容器从底部左侧滑动到底部侧隐藏状态。 4.可根据需求自定义的点击事件、出/隐藏动画效果和定时器等。 总之,使用jQuery推送消息完成类似于美团的下角功能,是一种简单、方便、易用的实现方式。 ### 回答3: 要实现类似于美团下角的效果,可以使用jQuery推送消息插件。该插件支持在网页中创建自定义的,并按照设定的方式进行推送。 首先,在页面中引入jQuery库和jquery推送消息插件,之后可以在JavaScript文件中进行如下操作: 1. 定义推送消息的内容和样式: var options = { 'title': '新消息提醒', 'text': '您有一条新的优惠信息,快来看看吧!', 'sticky': true, 'time': '', 'class_name': 'my-sticky-class' }; 2. 调用插件的方法: $.sticky(options); 其中,options是一个对象,包含了的标题(title)、内容(text)、是否固定不消失(sticky)、自动关闭的时间(time)、自定义类名(class_name)等参数。 3. 设定样式和位置: .sticky { background-color: #FFFFFF; border: 1px solid #DDDDDD; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1); color: #444444; font-family: 'Arial', sans-serif; font-size: 14px; line-height: 1.5em; margin-top: 10px; padding: 10px 15px; position: absolute; right: 0; bottom: 0; width: 300px; } 通过调整样式和位置,可以使呈现出美观且醒目的效果。 总之,使用jQuery推送消息插件,可以轻松实现类似于美团下角的效果,且可根据需求进行自定义设置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值