AngularJS implements button prompts and click color effects, and angularjs changes color

Source: Internet
Author: User

AngularJS implements button prompts and click color effects, and angularjs changes color

This article uses angularJS to easily implement a small button prompt, which will change color after the button is clicked. Note that jquery. js and angular. js need to be introduced in the html file.

Run:

When you click the button, the style of the button changes:

Css code:

<style type="text/css">  *{margin: 0px;padding: 0px;}  .bucSelectedButton{width: 100px;line-height: 30px;text-align: center;position: relative;}  .bucSelected {border:1px solid rgb(195,195,195);color:#000;cursor: pointer;border-radius: 6px;background-color: rgb(255,255,255);}  .bucSelectedHover{border: 1px solid rgb(74,201,255);color: rgb(74,201,255);cursor: pointer;border-radius: 6px;background-color: rgb(238,249,254);}  .bucSelectedHover .tip {color: rgb(0,0,0);background-color: rgb(255,255,255);} </style>

Html code:

<Div ng-controller = "bucTipController"> <! -- Command --> <buc-button id = "numberType" my-title = "button" tip-title = "this is the prompt" style = "margin-top: 60px; "> </buc-button> </div>

Js Code:

<script type="text/javascript">var app = angular.module("tip",[]);app.controller("bucTipController",function(){}).directive("bucButton",function(){ return {  restrict : 'E',  replace : true,  scope : {   myTitle : "@",   id : "@",   tipTitle : "@"  },  template : "<button class='bucSelectedButton bucSelected' ng-click='clicked()' ng-mouseover = 'mouseover()' ng-mouseout = 'mouseout()'>{{myTitle}}\    <div style='border:1px solid #dcdcdc;border-radius:6px;width:auto;height:20px;line-height:20px;position:absolute;top:-40px;padding:5px;white-space:nowrap;background-color:#fafafa;display:none;color:#000;left:20px;' class='tip'>{{tipTitle}}\     <span style='position:absolute;top:25px;left:10px;background-color:#fafafa;border:1px solid #dcdcdc;width:10px;height:10px;transform:rotate(45deg);border-left:none;border-top:none;'>\     </span>\    </div>\    </button>",  link : function(scope,elem,attrs) {   scope.mouseover = function(){    $(".tip").show();   }   scope.mouseout = function(){    $(".tip").hide();   }   scope.clicked = function(){    elem.toggleClass("bucSelectedHover");    $(".tip").hide();   }  } }})</script>

When you move the cursor to the button, the tip prompt appears. When you move the cursor out, the tip disappears. The small triangle of tip is implemented using the attributes of css3.

Summary

The above is all the content of this article, hoping to help you learn AngularJS. If you have any questions, you can leave a message.

Related Article

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.