Sometimes there are several news or message prompts. You can use absolute to locate the results.
What is the principle?
1. Obtain the number or status.
Copy codeThe Code is as follows:
Function getnewscount (){
$ Time = date ("Y-m-d", strtotime ("-3 day "));
$ Where ["News. checkked =? "] = Array (" val "=> 1," type "=> 1 );
$ Where ["News. UpdateTime >=? "] = Array (" val "=> $ time," type "=> 1); // '2017-01-10'
$ News = $ this-> dao_news-> getNews ($ where );
Return count ($ news );
}
Function getstatus ($ user_id ){
$ Where ["lx_messageto.user_id =? "] = Array (" val "=> $ user_id," type "=> 1 );
$ Where ["lx_messageto.status =? "] = Array (" val "=> 1," type "=> 1 );
$ Message = $ this-> dao_message-> getMessageTo ($ where );
Return count ($ message );
}
2. Front-End Processing Display. Processing with js.
Copy codeThe Code is as follows:
<Div style = "position: absolute;" class = "status1">
<! -- {If $ statusCount neq ""} -->
<Div class = "status_num">
<! -- {$ StatusCount} -->
</Div>
<! -- {/If} -->
</Div>
<Div style = "position: absolute;" class = "status2">
<! -- {If $ newsCount neq ""} -->
<Div class = "status_icon">
</Div>
<! -- {/If} -->
</Div>
Css
Copy codeThe Code is as follows:
. Status_num {
Position: absolute;
Left: 70px; top: 0px;
Background-image:-webkit-gradient (linear, 0 0, 0 bottom, from (rgba (234, 87,122, 1), to (rgba (136, 4, 25, 1 )));
Height: 30px; line-height: 30px;
Vertical-align: middle;
Font-family: Verdana, Geneva, sans-serif; color: # fff;
Font-size: 14px;-webkit-border-radius: 30px;
Padding: 0px 10px; margin-left: 20px;
-Webkit-box-shadow: 1px 1px 3px #999 ;}
. Status_icon {
Position: absolute;
Left: 70px; top: 0px;
}
Js Processing
Copy codeThe Code is as follows:
$ (Function (){
AMess = $ ("a [href ^ = '/message']");
ANews = $ ("a [href ^ = '/news/Index']");
Var status = $ (". status1 ");
Var statusnews = $ (". status2 ");
ANews. prepend (statusnews );
AMess. prepend (status); // process the message
});
3. You can also use ajax to obtain data for ajax processing.
Copy codeThe Code is as follows:
$ (Function (){
If ($ ("a [href * = '/news/mgr']")! = ""){
ANews = $ ("a [href * = '/news/mgr']");
$. Ajax ({
DataType: 'html ',
Type: "POST ",
Url: "/default/index/ajaxgetnewstatus ",
Success: function (msg ){
If (msg> 0 ){
Var num = '<div style = "position: absolute;" class = "status1">'
+ '<Div class = "status_num">' + msg + '</div> ';
ANews. prepend (num );}
}
});
};
});