Js achieves Automatic Webpage running after double-clicking ------- Day55

Source: Internet
Author: User

The company's interface design process has finally come to an end. It must be acknowledged that the evening study has brought me many benefits. The occasional application at work has surprisingly good results, I am very pleased to receive some small comments from the leaders and colleagues, and have gained a lot of confidence. Although I do not understand it, people who have been working for several years should not be familiar with this. Why is it strange? But they don't want to be so much. Just like it.

Today, we will record how to automatically run the webpage after js is double-clicked. This is reflected in many websites. How can we achieve this?

First, let's analyze the basic principles of implementation:

1. Get the double-click event of the mouse (this was recorded once before, but unfortunately it seems that an error was still written last time. Here, correct ondblclick, the case sensitivity in javascript is really worth noting );

2. Automatic Webpage running. That is to say, the page rolling effect is actually scrollTop increasing until it reaches the bottom;

Use the code to implement the following:

Var nowPostion, timer; document. onmousedown = stop; document. ondblclick = windowScroll; // remember, it's ondbclick, all in lower case function windowScroll () {// var windowScroll = function (){}, do you still remember this writing? timer = setInterval ("scrollwindow ()", 1);} function stop () {clearInterval (timer);} function scrollwindow () {// This is the key to implementation: nowPostion = document. body. scrollTop; // The upper distance of the current scroll bar from window. scroll (0, ++ nowPostion); // here is ++ nowPostion, not nowPostion ++ Oh if (n OwPostion! = Document. body. scrollTop) // This is ++'s previous stop ();}
Record several key points:

1. Double-click the event and ondbclick event, and declare it again;

2. window. scroll (1,100); similar to this method, what does it mean?

In fact, we need to know the true meaning of the parameter first. The parameter can be considered as a coordinate, representing the starting point in the upper left corner. Based on the distance at the top of the page and the distance at the leftmost end, then we can understand whether this event is much easier. In pixels, the event is moved from the upper left corner to the specified point.

3. Auto-increment, first ++ or later ++, first ++ indicates first + 1 and then operation; then ++ indicates first data operation, then + 1;


It's beautiful to know new things ..



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.