dir.by  
Поиск >>

Компьютер, программы
→
Html & CSS
 Открываю web страницу на телефоне в Google Chrome. Почему при двойном нажатии размер страницы увеличивается? 
посмотрели 3543 раз
обновлено: 15 October 2024
Решение
  Html  
<style>
     * {
          touch-action: manipulation; // double click not zoom on phone
     }
</style>
Пример 1. Рисуем линии по нажатию на Canvas
Напишем код чтобы рисовались линии по нажатию мышкой на компьютере или тыкаем пальцем на телефоне:
  Html  
<html>
     <head>
          <meta charset="utf-8">
          <title>My canvas</title>
     </head>

     <body>
          <center>
               <canvas id='myCanvas1' style='background-color:white; border:1px solid black;' width='600px' height='400px'/>
          </center>
     </body>

     <script>
          var myCanvas = document.getElementById("myCanvas1");
          myCanvas.onmousedown = MyClickCanvas;
          var context = myCanvas.getContext('2d');

          var lastX = null;
          var lastY = null;

          function MyClickCanvas(e)
          {
               const rect = myCanvas.getBoundingClientRect();
               var x = e.clientX - rect.x;
               var y = e.clientY - rect.y;

               if (lastX!=null && lastY!=null)
                    MyDrawLine(context, 'black' /*color*/, 2 /*line width*/, lastX, lastY, x, y);

               lastX = x;
               lastY = y;
          }

          function MyDrawLine(context, lineColor, lineWidth, x1, y1, x2, y2)
          {
               context.resetTransform();
               context.beginPath();
               context.moveTo(x1, y1);
               context.lineTo(x2, y2);
               context.lineWidth = lineWidth;
               context.strokeStyle = lineColor;
               context.stroke();
          }
     </script>

     </body>
</html>
Example we look, we test
При двойном нажатии на телефоне размер страницы увеличивается:
Пример 2. Рисуем линии по нажатию на Canvas
в код добавим чтобы при двойном нажатии на телефоне размер страницы НЕ увеличивался:
  Html  
<style>
     * {
          touch-action: manipulation; // double click not zoom on phone
     }
</style>
Вот весь код:
  Html  
<html>
     <head>
          <meta charset="utf-8">
          <title>My canvas</title>
     </head>

     <style>
          * {
               touch-action: manipulation; // double click not zoom on phone
          }
     </style>


     <body>
          <center>
               <canvas id='myCanvas1' style='background-color:white; border:1px solid black;' width='600px' height='400px'/>
          </center>
     </body>

     <script>
          var myCanvas = document.getElementById("myCanvas1");
          myCanvas.onmousedown = MyClickCanvas;
          var context = myCanvas.getContext('2d');

          var lastX = null;
          var lastY = null;

          function MyClickCanvas(e)
          {
               const rect = myCanvas.getBoundingClientRect();
               var x = e.clientX - rect.x;
               var y = e.clientY - rect.y;

               if (lastX!=null && lastY!=null)
MyDrawLine(context, 'black' /*color*/, 2 /*line width*/, lastX, lastY, x, y);

               lastX = x;
               lastY = y;
}

          function MyDrawLine(context, lineColor, lineWidth, x1, y1, x2, y2)
          {
               context.resetTransform();
               context.beginPath();
               context.moveTo(x1, y1);
               context.lineTo(x2, y2);
               context.lineWidth = lineWidth;
               context.strokeStyle = lineColor;
               context.stroke();
          }
     </script>

     </body>
</html>
Example we look, we test
 
← Previous topic
Drawing a picture with movement and animation (sprite). Use the HTML element <canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval
 
Next topic →
What the Front-end development?
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Новость "Черная пятница" Dreame в Беларуси – две недели скидок до 3400 рублей
 
HTML elements
• HTML tag <a> link to go to another page
• HTML tag <abbr> shows an abbreviated name, if you let the mouse down there will be a pop-up inscription
• HTML tags fieldset and legend. This is a frame with a title
• HTML tag <!-- --> comment
• style="border" in the HTML
<BR>
HTML search for an element, elements
• document.querySelector(...) is a JavaScript method for finding an element from document (i.e. in all HTML)
• yourElement.querySelectorAll(...) is a JavaScript method for finding elements inside another HTML element
<BR>
HTML svg (vector graphics for drawing lines, rectangles, ellipses, ...)
• <svg> vector graphics, drawing a line<line>, rectangle <rect>, circle<circle>, text<text>
<BR>
HTML canvas (drawing pictures, text, shapes)
• HTML <canvas> drawing a rectangle
• HTML drawing <canvas> lines by clicking on the Canvas
• HTML <canvas> we draw pictures
• HTML <canvas> we draw a picture with a rotation
• HTML <canvas> draw a picture with horizontal reflection
• HTML <canvas> we draw a picture and text
• HTML <canvas> draw a picture many times in a rectangle (template)
• HTML <canvas> how to get mouse coordinates ? Determine the position of the mouse.
• HTML <canvas> drawing a snake with lines moveTo, lineTo
CSS
• CSS description
• After modifying the file css , the browser displays old styles over and over again. Why?
• Books to study CSS
CSS flex (the element can stretch or shrink and thus fill the free space)
• What is CSS flex
Freeze
• The header in the table is always visible when scrolling | freeze header in table | HTML
• Div is always visible when scrolling (position:fixed, position:sticky) | freeze div | HTML
Do Popup using HTML and Javascript
• How to make a Popup window in a HTML page | Javascript, HTML, CSS
Motion and animation of pictures
• Animation of the little man on the spot. For <div>animation, we use CSS styles: "animation", "background-image", "background-position", "keyframes"
• Animation of a man in motion (sprite). For <div><img>animation we use CSS styles: "animation", "background-image", "background-position", "keyframes"
• Draw a picture with movement. Use the HTML element<canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval
• Drawing a picture with movement and animation (sprite). Use the HTML element <canvas>. Use JavaScript for movement: var img = new Image(), img.src = url, drawImage, timer, window.setInterval
Web page on the phone
• I open a web page on my phone in Google Chrome. Why does double-clicking increase the page size?
Layout, page design
• What the Front-end development?
• How to Identify a Device (Tablet, Computer, Phone) Currently Used in JavaScript, HTML
• How to make your site work on a phone, tablet, computer using css media and max-device-width and min-device-width | HTML | CSS
• How to make your website fit in size on your phone, tablet? (HTML meta with attribute name="viewport")
• Correct layout HTML. Bad to use table. You need to use div
• What is Adaptive design? What is responsive design?
• Change the color of the scrollbar for the HTML page. Using CSS
WWW sites for learning
• Sites to explore HTML

  Ваши вопросы присылайте по почте: info@dir.by