Implementation case of floating numbers

Source: Internet
Author: User

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 );}
}
});
};
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.