JavaScript implements simple scroll window

JavaScript implements simple scroll window

This article example shares the specific code of JavaScript to implement the scroll window for your reference. The specific content is as follows

1. Implementation effect diagram

2. Knowledge points involved

The window.open() method is used to open a new browser window or find a named window.

moveTo(): ​​The method can move the upper left corner of the window to a specified coordinate.

window.screen.height: screen pixel height

window.screen.width: the width of the screen in pixels

window.screenLeft; The distance from the left side of the screen

window.screenTop; the distance from the top to the screen

setTimeout: The method is used to call a function or calculate an expression after a specified number of milliseconds, setTimeout(function, milliseconds).

3. Code Implementation

<!DOCTYPE html>
<html lang="utf-8">
<head>
    <meta charset="UTF-8">
    <title>Scrolling Window</title>
    <script>  
        var w ;//page width var h;//page height var x;//horizontal distance from the screen var y;//vertical distance from the screen var v = 5;//horizontal position of each movement var s = 8;//vertical position of each movement function windowOpen(){
        mywindow = window.open('','','width=200px,height=100px');
        mywindow.document.write("This is an open window");
           w =window.screen.width;
           h=window.screen.height;
           x=window.screenLeft;
           y=window.screenTop;
           windowmove();
       
      }
      function windowmove(){
       if(x<0||x>w){
        s=-s; 
       }
       x=x+s;
       if(y<0||y>h){
        v=-v;
       }
        y=y+v;
        mywindow.moveTo(x,y); 
        setTimeout(windowmove,10);
      }
      
 
    </script>
</head>
<body>
    <input type="submit" value="Open window" id="windowOpen" onclick="windowOpen()">
</body>
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JS implements displaying/hiding window fixed position elements as the page scrolls
  • js+css to realize the mask centered pop-up layer (scrolling with the browser window scroll bar)
  • javascript window width and height, mouse position, scroll height (detailed analysis)
  • JavaScript gets the scroll position code of the modal window
  • js/jquery obtains the browser window visible area height and width and scroll bar height implementation code
  • JavaScript uses DIV to simulate pop-up windows_form scrolling follows

<<:  Practical method of upgrading PHP to 5.6 in Linux

>>:  Explanation of the problem of selecting MySQL storage time type

Recommend

MySQL complete collapse: detailed explanation of query filter conditions

Overview In actual business scenario applications...

Zen HTML Elements Friends who use zen coding can collect it

html ¶ <html></html> html:xml ¶ <h...

How to set up Spring Boot using Docker layered packaging

The Spring Boot project uses docker containers, j...

JavaScript function detailed introduction

Any number of statements can be encapsulated thro...

TCP performance tuning implementation principle and process analysis

Three-way handshake phase Number of retries for c...

How to implement the @person function through Vue

This article uses vue, and adds mouse click event...

Common front-end JavaScript method encapsulation

Table of contents 1. Enter a value and return its...

Example of how to deploy a Django project using Docker

It is also very simple to deploy Django projects ...

Two ways to remove the 30-second ad code from Youku video

I believe everyone has had this feeling: watching ...

Add a copy code button code to the website code block pre tag

Referring to other more professional blog systems...

Summary of Mysql exists usage

Introduction EXISTS is used to check whether a su...

Install Percona Server+MySQL on CentOS 7

1. Environmental Description (1) CentOS-7-x86_64,...

js+css to realize three-level navigation menu

This article example shares the specific code of ...

How to deploy SpringBoot project using Dockerfile

1. Create a SpringBooot project and package it in...