最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to implement notification number on buttons in jquery mobile? - Stack Overflow

programmeradmin7浏览0评论

I am making a jquery mobile app. I want to add a notification number to a button defined like this.

<a id="resource-button" href="#" data-role="button" data-icon="info" data-iconpos="left">Resources</a> 

Basically I want it so that, if the number is > 0, then it should look like this:

And if its = 0, then the number icon should not show at all.

How can I implement this?

Thanks

I am making a jquery mobile app. I want to add a notification number to a button defined like this.

<a id="resource-button" href="#" data-role="button" data-icon="info" data-iconpos="left">Resources</a> 

Basically I want it so that, if the number is > 0, then it should look like this:

And if its = 0, then the number icon should not show at all.

How can I implement this?

Thanks

Share Improve this question asked Feb 13, 2015 at 7:50 omegaomega 44k90 gold badges286 silver badges523 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

HTML

<div id="icon">
    <div id="not">3</div>
</div>

CSS

#icon
{
    height:100px;
    width:100px;
    background-color:#bbb;
    position:relative;

}
#not
{
    position:absolute;
    top:-10px;
    right:-10px;
    background-color:#f00;
    width:20px;
    height:20px;
    color:#fff;
    border-radius:20px
    -moz-border-radius:20px;
    -webkit-border-radius:20px;
    text-align:center;
    border:2px solid #fff;

}

JQuery

$(document).ready(function(){
   if($("#not").html()=="0") $("#not").hide();  
});

Attached Fiddle

http://jsfiddle/gwqn2eqa/

//HTML

<ul data-role="listview">
    <li><a href="http://www.shreerangpatwardhan.blogspot.">Spatial Unlimited</a>
        <div class="ui-li-count">158</div>
    </li>
    <li><a href="http://shreerangpatwardhan.blogspot.in/p/code-samples.html">Google Maps API Examples</a>
        <div class="ui-li-count">0</div>
    </li>
    <li><a href="http://shreerangpatwardhan.blogspot.in/p/jquery-mobile.html">Jquery Mobile Examples</a>
        <div class="ui-li-count">1</div>
    </li>
    <li><a href="http://www.facebook./SpatialUnlimited">Facebook likes - Spatial Unlimited</a>
        <div class="ui-li-count">12</div>
    </li>
</ul>

//JS

$(document).ready(function () {
    $.each($('.ui-li-count'), function (i, v) {
        if($(this).html() == 0) {
            $(this).hide();
        }
    });
});

without listview :

//html

<span class="ui-li-count ui-btn-corner-all countBubl">12</span>

//css

.countBubl {float:left;margin-top:-42px;margin-left:35px;background:#ed1d24;color:#fff;padding:2px;}

first of all you have to make row in your database to check post is seen or not for example we get it as status with true and false values .

When user send a new message you add it to database with status false. it's means user already don't see message .
in your code we add new attribute for <a> link as notification

<a id="resource-button" notification="4" href="#" data-role="button" data-icon="info" data-iconpos="left">Resources</a> 

in this case we have 4 new notificcation for user .

first of all we have to check if notification attribute exists or is not equal to 0 then we make notifi box .

$(document).ready(function() { 

if( $("#resource-button").hasAttr("notification")) { 
    var num = $("#resource-button").val("notification") ; 
    if (num > 0) { 
        $("#number").css("display", "block") ; 
        $("#number").text(num); 
    }
}
});

CSS for #number :

    #number { 
height: 18px;
width: 18px;
background: url("../images/notification-bg-clear.png") no-repeat scroll center center #F56C7E;
position: absolute;
right: 5px;
top: -10px;
color: #FFF;
text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);
text-align: center;
font-size: 9px;
line-height: 18px;
box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.17) inset, 0px 1px 1px rgba(0, 0, 0, 0.2);
border-radius: 9px;
font-weight: bold;
cursor: pointer;
}
发布评论

评论列表(0)

  1. 暂无评论