JS implementation of custom right mouse button-------Day45

Source: Internet
Author: User

Another weekend, but in fact, this is a week in foreign countries should be the beginning of it, anyway, today is in the rest, relax my tense nerves, relax me some tired spirit, last night to crack a headache, as if all the data in the brain literally dancing, accompanied by a burst of nausea, at that time the daughter-in-law to frighten, I really do not know how Kobe Bryant every day to see the four o'clock in the morning sun, this constitution can not be said, and there is a point is to have to say that the body is really the root of all, friendship suggest friends or good exercise body, I also want to exercise well.

Review this week, the project leader of a sentence to me a great touch, the exact words I do not remember how to say, it is probably meant to say: no matter how much you will, you have to use the is your. In fact, that sentence at the time of the situation should be some far-fetched, even say is wrong, but still let me sigh unceasingly. Looking back at the initial job search, write on the resume what will be, go to interview ask you understand what, and then test that, but to the work is not necessarily all used, and even some when you use on the time, you only find that you will actually still useless, but also to learn, this and my initial work experience is different, At that time, a piece of the area, in their own area to how to toss how to toss, solve the problem is good, and this inertial way of thinking let me in the industry this is initially painful, to this will be as if suddenly want to understand the same: do everything to abide by the rules, and the existence of rules may feel is bound their own play, But the overall progress of the project can be more convenient, because the rules are there, a project team is guarding the specification, in the integration of the time is much simpler.

Of course also understand a lot, are opinion, is not in this disgraced, in fact, if the school is to let people learn the knowledge, the company is let people learn how to use, probably this is the student's time we always in the feeling learned things useless reason, after all, the internal strength of thousands of years, no moves words are false bar.

Ramble said a lot, say the basics turn, today to record JS from the definition of the right mouse button, the same first to decompose its implementation principle:

1, Shielding right-click Default event; (At one point I thought that the default event was changed)

2, to a UL of the hidden; (This I have also been pedantic to think that it is worth doing this is Div, Khan)

3, the right mouse button to make the response, showing the hidden ul;

4, after the mouse re-click, the UL is hidden again

In this way, what we need to do is not a lot simpler, first on the code:

HTML section

<ul id= "Testright" style= "width:100px;background-color:yellow;position:absolute;z-index:100;" >    <li><a href= "#" > Start </a></li>    <li><a href= "#" > Pause </a></li >    <li><a href= "#" > Bye </a></li></ul>
JavaScript section:

Window.onload=function () {var Forright=document.getelementbyid ("Testright");//Get the object, now too familiar with forright.style.display= "None"; var title=forright.getelementsbytagname ("Li"); for (Var i=0;i<title.length;i++) {title[i].onmouseover= function () {this.classname= "active";//actually we can call other events here};title[i].onmouseout=function () {// Here is also a mouse two events bar This.classname= "";};} Document.oncontextmenu=function (Event) {//This is the key point of implementation var event=event| | window.event;//, this is not a problem. forright.style.display= "block"; forright.style.left=event.clientx+ "px"; forright.style.top=event.clienty+ "px";//mouse coordinates AH return false;//here return false is to block the default event};d ocument.onclick=function () {/ /Just for a more image imitation Ah forright.style.display= "none";};
Let's take a look at the key point of today's record: Document.oncontextmenu This event returns false is to block the default event, if we do not write, only in this event write return, as if the following

Document.oncontextmenu=function () {     return false;}
in this case, the right-click button will not respond any more. Then return to see the whole event application, as if in addition to this event, the other is more familiar with the event, can be the event of this integration is always lacking, the key or idea is creative bar, but first no matter where more, first the whole bar, but for 3,000, not to write to only ask Yin. Tie horse, tie horse, tie horse ...


In fact, when I first saw "Harry Potter", I was particularly envious of his magic broom, every day to take care of cleaning, reading is also looking at the broom and so on, as if to think of ancient swordsman, can be so pious. I am very fortunate, so long ago found oneself willing to struggle of things, I would like to take a pilgrimage heart, forward ....





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.