A method and device for page adaptive layout based on rem

By converting page component units to rem and setting the root node size unit, and generating CSS style files using adaptive scaling, the high complexity of implementing adaptive page design in existing technologies is solved. This achieves a unified layout across different terminal devices, improving development efficiency and user experience.

CN113934339BActive Publication Date: 2024-11-29SHENZHEN COMTOP INFORMATION TECH
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202111074187.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-14
Publication Date
2024-11-29
Estimated Expiration
2041-09-14

AI Technical Summary

Technical Problem

Existing technologies require writing multiple style files and complex code processing to achieve adaptive page layouts, resulting in high complexity and making it difficult to achieve a unified page layout across different terminal devices.

Method used

By converting the units of page components to rem units and setting the size unit of the root node, combined with adaptive scaling, a CSS style file is generated to achieve adaptive page layout.

Benefits of technology

It reduces the complexity of implementing adaptive page layout, improves the efficiency of multi-terminal web page development and maintenance, and enhances the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113934339B_ABST
    Figure CN113934339B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for page adaptive layout based on rem, the method comprising: determining a reference canvas, and determining the first size of all components; determining the corresponding conversion unit according to the adaptive scaling mode; setting the root node font size unit as the conversion unit; determining the original adaptive viewport range; converting the first size of all components into a second size in rem units and converting the original adaptive viewport range into a target adaptive viewport range in rem units; generating a CSS style file according to the second size of all components, the root node font size unit and the target adaptive viewport range. It can be seen that the implementation of the present invention can convert the unit of the component into the rem unit and set the root node font size unit, realize the page adaptive layout on the terminal device, which is conducive to reducing the complexity of page adaptive implementation and improving the efficiency of multi-terminal web page development and maintenance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of page layout, and in particular to a method and device for page adaptive layout based on rem. Background Art

[0002] With the rise of terminal devices with various screen sizes, it is necessary to allow components to present the same content and layout on terminal devices of different sizes to achieve page adaptation and thus achieve a better user experience.

[0003] Currently, there are usually two ways to achieve page adaptation: one is to detect the viewport resolution based on multimedia query responsive technology, and perform code processing on the terminal device side based on the detected viewport resolution to display different layouts and content. This method requires writing multiple sets of styles for different screen sizes to display different content and layouts, thereby achieving the adaptive effect, which increases the complexity of implementation; the other is to determine the type of terminal device currently accessed by detecting the viewport resolution, and request the service layer to return a matching page to achieve the adaptive effect. This method requires maintaining multiple versions of style files, which increases the complexity of implementation. It can be seen that it is particularly important to provide a new method for content page adaptation to reduce the complexity of implementation. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a method and device for page adaptive layout based on rem, which can realize page adaptation on different terminal devices by converting the units of all components of the page into rem units and setting the root node size unit, thereby reducing the complexity of page adaptation implementation, which is beneficial to improving the efficiency of multi-terminal web page development and maintenance, and is beneficial to improving the user experience of using the page.

[0005] In order to solve the above technical problem, the first aspect of the present invention discloses a method for page adaptive layout based on rem, the method comprising:

[0006] Determine a reference canvas, and determine a first size of each of the components displayed on the reference canvas according to the size of the original design drawing, wherein the unit of the first size of each of the components is a pixel unit;

[0007] According to a predetermined adaptive scaling method, determining a conversion unit corresponding to the adaptive scaling method, and converting a target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, wherein the unit of the target value is the conversion unit;

[0008] Set the root node font size unit to the conversion unit;

[0009] Determine an original adaptive viewport range in pixels, where the original adaptive viewport range includes an original viewport width range and / or an original viewport height range;

[0010] Convert the first size of all the components into a second size in rem, and convert the original adaptive viewport range into a target adaptive viewport range in rem;

[0011] A CSS style file is generated according to the second sizes of all the components, the root node font size unit, and the target adaptive viewport range.

[0012] As an optional implementation manner, in the first aspect of the present invention, determining, according to a predetermined adaptive scaling mode, a conversion unit corresponding to the adaptive scaling mode includes:

[0013] When the adaptive scaling mode is a first adaptive mode based on page width, determining that the conversion unit corresponding to the adaptive scaling mode is a page viewport width VW;

[0014] When the adaptive scaling mode is the second adaptive mode based on the page height, it is determined that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH.

[0015] As an optional implementation manner, in the first aspect of the present invention, determining the original adaptive viewport range in the pixel unit includes:

[0016] Obtaining a result of a multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, and setting a maximum value and a minimum value of a target size type in a size type of a viewport that matches the adaptive scaling method as responsive breakpoints;

[0017] According to the adaptive scaling mode and the maximum and minimum values ​​of the target size type, a size range of the target page for displaying all the components is set to determine an original adaptive viewport range in pixels.

[0018] As an optional implementation manner, in the first aspect of the present invention, the result of the multimedia query includes:

[0019] At least one of a width range and / or a height range of each viewport in a plurality of viewports, a width range and / or a height range of each page in a plurality of pages, and device parameters of a plurality of terminal devices;

[0020] The device parameters of each terminal device include one or more of width, height, type, and resolution.

[0021] As an optional implementation, in the first aspect of the present invention, setting the size range of the target page for displaying all the components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type includes:

[0022] When the adaptive scaling mode is the first adaptive mode, the maximum value of the width of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the width of the target page is set to the minimum value of the target size type;

[0023] When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

[0024] As an optional implementation, in the first aspect of the present invention, before setting the root node font size unit as the conversion unit, the method further includes:

[0025] Building a Sass project using Sass syntax, and determining a conversion relationship between the pixel unit and the conversion unit according to the Sass project;

[0026] The conversion relationship is used to convert the acquired size of any node font into a size with the conversion unit as the unit.

[0027] As an optional implementation, in the first aspect of the present invention, converting the first sizes of all the components into second sizes in rem units, and converting the original adaptive viewport range into a target adaptive viewport range in rem units, comprises:

[0028] Configure the pxtorem project, and convert the first size of all the components into the second size in rem through the PostCss loader of Webpack combined with the Postcss-pxtorem plug-in, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

[0029] A second aspect of the present invention discloses a device for page adaptive layout based on rem, the device comprising:

[0030] A determination module, used to determine a reference canvas, and determine a first size of each of all components displayed on the reference canvas according to the size of the original design drawing, wherein the unit of the first size of each component is a pixel unit;

[0031] The determination module is further used to determine the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method;

[0032] a conversion module, configured to convert a target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, wherein the unit of the target value is the conversion unit;

[0033] A setting module, used to set the root node font size unit to the conversion unit;

[0034] The determination module is further used to determine an original adaptive viewport range in units of pixels, wherein the original adaptive viewport range includes an original viewport width range and / or an original viewport height range;

[0035] The conversion module is further used to convert the first sizes of all the components into second sizes in rem units, and convert the original adaptive viewport range into a target adaptive viewport range in rem units;

[0036] A generating module is used to generate a CSS style file according to the second sizes of all the components, the root node font size unit and the target adaptive viewport range.

[0037] As an optional implementation, in the second aspect of the present invention, the determination module determines the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method in a manner as follows:

[0038] When the adaptive scaling mode is a first adaptive mode based on page width, determining that the conversion unit corresponding to the adaptive scaling mode is a page viewport width VW;

[0039] When the adaptive scaling mode is the second adaptive mode based on the page height, it is determined that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH.

[0040] As an optional implementation, in the second aspect of the present invention, the determination module determines the original adaptive viewport range in the pixel unit in the following manner:

[0041] Obtaining a result of a multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, and setting a maximum value and a minimum value of a target size type in a size type of a viewport that matches the adaptive scaling method as responsive breakpoints;

[0042] According to the adaptive scaling mode and the maximum and minimum values ​​of the target size type, a size range of the target page for displaying all the components is set to determine an original adaptive viewport range in pixels.

[0043] As an optional implementation, in the second aspect of the present invention, the result of the multimedia query includes:

[0044] At least one of a width range and / or a height range of each viewport in a plurality of viewports, a width range and / or a height range of each page in a plurality of pages, and device parameters of a plurality of terminal devices;

[0045] The device parameters of each terminal device include one or more of width, height, type, and resolution.

[0046] As an optional implementation, in the second aspect of the present invention, the determination module sets the size range of the target page for displaying all the components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type in the following manner:

[0047] When the adaptive scaling mode is the first adaptive mode, the maximum value of the width of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the width of the target page is set to the minimum value of the target size type;

[0048] When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

[0049] As an optional implementation, in the second aspect of the present invention, the device further includes:

[0050] A building module, used for building a Sass project by using Sass syntax before the setting module sets the root node font size unit to the conversion unit;

[0051] The determination module is further used to determine the conversion relationship between the pixel unit and the conversion unit according to the Sass project;

[0052] The conversion relationship is used to convert the acquired size of any node font into a size with the conversion unit as the unit.

[0053] As an optional implementation, in the second aspect of the present invention, the conversion module converts the first sizes of all the components into second sizes in rem units, and converts the original adaptive viewport range into a target adaptive viewport range in rem units in the following manner:

[0054] Configure the pxtorem project, and convert the first size of all the components into the second size in rem through the PostCss loader of Webpack combined with the Postcss-pxtorem plug-in, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

[0055] The third aspect of the present invention discloses another device for page adaptive layout based on rem, the device comprising:

[0056] A memory storing executable program code;

[0057] a processor coupled to the memory;

[0058] The processor calls the executable program code stored in the memory to execute the page adaptive layout method based on rem disclosed in the first aspect of the present invention.

[0059] The fourth aspect of the present invention discloses a computer storable medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the page adaptive layout method based on rem disclosed in the first aspect of the present invention.

[0060] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0061] In an embodiment of the present invention, a reference canvas is determined, and the first size of each component in all components displayed on the reference canvas is determined according to the size of the original design drawing, and the unit of the first size of each component is a pixel unit; according to a predetermined adaptive scaling method, a conversion unit corresponding to the adaptive scaling method is determined, and based on the conversion unit, the target rem unit is converted into a target value corresponding to 100 pixel units, and the unit of the target value is a conversion unit; the root node font size unit is set as the conversion unit; the original adaptive viewport range in pixel units is determined, and the original adaptive viewport range includes the original viewport width range and / or the original viewport height range; the first size of all components is converted into a second size in rem units, and the original adaptive viewport range is converted into a target adaptive viewport range in rem units; according to the second size of all components, the root node font size unit and the target adaptive viewport range, a CSS style file is generated. It can be seen that the implementation of the present invention is conducive to reducing the complexity of page development and maintenance, is conducive to improving the efficiency of multi-terminal web page development and maintenance, is conducive to conveniently realizing page dynamic adaptation, and thus is conducive to improving the user experience of using the page. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0063] Figure 1 It is a flow chart of a method for page adaptive layout based on rem disclosed in an embodiment of the present invention;

[0064] Figure 2 It is a flowchart of another method for page adaptive layout based on rem disclosed in an embodiment of the present invention;

[0065] Figure 3 It is a structural schematic diagram of a page adaptive layout device based on rem disclosed in an embodiment of the present invention;

[0066] Figure 4 It is a structural schematic diagram of another page adaptive layout device based on rem disclosed in an embodiment of the present invention;

[0067] Figure 5 It is a structural schematic diagram of another REM-based page adaptive layout device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION

[0068] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0069] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, product or end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products or ends.

[0070] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0071] The present invention discloses a method and device for page adaptive layout based on REM, which is conducive to reducing the complexity of page development and maintenance, improving the efficiency of multi-terminal web page development and maintenance, and conveniently realizing dynamic page adaptation, thereby improving the user experience of using the page. The following are detailed descriptions.

[0072] Embodiment 1

[0073] See also Figure 1 , Figure 1 : is a flow chart of a method for page adaptive layout based on rem disclosed in an embodiment of the present invention. Figure 1 The described method of page adaptive layout based on rem can be applied to terminal devices with display screens, such as PC (Personal Computer), notebook computers, tablet computers, mobile phones, etc., and the embodiments of the present invention are not limited thereto. Figure 1 As shown, the page adaptive layout method based on rem may include the following operations:

[0074] 101. Determine a reference canvas, and determine a first size of each component among all components displayed on the reference canvas according to the size of the original design drawing, where the unit of the first size of each component is a pixel unit.

[0075] In the embodiment of the present invention, the components displayed on the reference canvas include text, pictures, etc., which are not limited in the embodiment of the present invention. The sizes of all components displayed on the reference canvas are developed in pixel units in the original design drawing. Pixel refers to the basic encoding of basic primitive colors and their grayscales, and the pixel unit is a relative length unit.

[0076] 102. According to a predetermined adaptive scaling method, determine a conversion unit corresponding to the adaptive scaling method, and convert the target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, where the unit of the target value is the conversion unit.

[0077] In the embodiment of the present invention, the rem (root em) unit is a relative length unit with respect to the root element (html), and all font sizes in the page can be set according to the numerical size corresponding to the root element (html), wherein the method of setting all font sizes in the page according to the numerical size corresponding to the root element (html) can be to set them in a proportional manner.

[0078] In an embodiment of the present invention, the adaptive zooming method includes an adaptive method based on the page width and an adaptive method based on the page height. Optionally, the adaptive zooming method can be determined by the current usage status or orientation of the mobile device displaying the page. For example, when the current screen state of the mobile phone is a vertical screen state (for example: the mobile phone is placed vertically and the screen orientation is locked to vertical), the current adaptive zooming method is determined to be an adaptive method based on the page height. Optionally, the adaptive zooming method can also be determined by a multimedia query. For example, when the multimedia query result is used to indicate that the terminal device displaying the page is a computer PC, the device parameters of the computer PC are obtained, wherein the device parameters may include one or more of the model of the computer PC and the resolution of the computer PC, and the current adaptive zooming method is determined according to the obtained device parameters of the computer PC.

[0079] In an embodiment of the present invention, the adaptive scaling method can be determined by detecting the screen condition of the terminal device displaying the page, and can also be determined by obtaining the device parameters of the terminal device displaying the page. Determining the adaptive scaling method by detecting the screen condition of the terminal device and obtaining the device parameters of the terminal device is beneficial to improving the accuracy of determining the adaptive scaling method, and is also beneficial to improving the convenience of determining the adaptive scaling method.

[0080] In another optional embodiment, determining the conversion unit corresponding to the adaptive scaling mode according to the predetermined adaptive scaling mode may include:

[0081] When the adaptive scaling mode is the first adaptive mode based on the page width, determining that the conversion unit corresponding to the adaptive scaling mode is the page viewport width VW;

[0082] When the adaptive scaling mode is the second adaptive mode based on the page height, it is determined that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH.

[0083] In the embodiment of the present invention, the viewport is the screen area in the display screen of the terminal device that displays the page content, the viewport size is the size of the screen area in the display screen of the terminal device that displays the page content, and the page viewport width VW (Viewport Width) and the page viewport height VH (Viewport Height) are viewport units. Further optionally, when the page is adaptively laid out on the PC side, the viewport refers to the visible area of ​​the browser in the display screen of the PC side; when the page is adaptively laid out on the mobile side, the viewport includes three types: layout viewport (Layout Viewport), visual viewport (Visual Viewport), and ideal viewport (Ideal Viewport). Among them, the layout viewport (LayoutViewport) refers to the size of the page. According to different types of terminal devices, each type of terminal device has a size corresponding to the type of terminal device; the visual viewport (Visual Viewport) refers to the area of ​​the page seen by the user on the terminal device, wherein the area of ​​the page seen by the user can be equivalent to the size of the browser window on the terminal device; the ideal viewport (Ideal Viewport) refers to the size of the most ideal browsing and reading on the browser of the terminal device. In the case of the ideal viewport, the size of the layout viewport is consistent with the screen size of the terminal device, that is, the user can browse all the page contents without scrolling the page up and down or sliding the page left and right. In an embodiment of the present invention, when performing page adaptive layout on a mobile terminal, the object targeted by the page adaptive layout is the layout viewport (LayoutViewport).

[0084] In the embodiment of the present invention, optionally, the target rem unit may be 1rem, and when it is determined that the adaptive scaling mode is the first adaptive mode based on the page width, and the conversion unit corresponding to the first adaptive mode is the page viewport width VW, the value of the page viewport width VW corresponding to 100 pixel units converted from 1rem is determined. For example, the value of the page viewport width VW corresponding to 100 pixel units converted from 1rem may be 1rem=6.25vw=100px.

[0085] It can be seen that the embodiment of the present invention can determine the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method, which can reduce the complexity of page development and maintenance, is conducive to improving the efficiency of multi-terminal web page development and maintenance, and is conducive to improving the convenience of page adaptive layout.

[0086] 103. Set the root node font size unit to the conversion unit.

[0087] In an embodiment of the present invention, the root node font size can be set according to the font-size field of the root element (html element) of the web page, and the set reference value can be the initial value of the font size of the root node of the web page pre-set by the developer when designing the web page.

[0088] In the embodiment of the present invention, the conversion unit includes the page viewport width VW and the page viewport height VH. When the determined conversion unit is the page viewport width VW, the root node font size unit is set to the page viewport width VW; when the determined conversion unit is the page viewport height VH, the root node font size unit is set to the page viewport height VH.

[0089] It can be seen that in the embodiment of the present invention, the root node font size unit is set as the conversion unit, wherein the conversion unit includes the page viewport width VW and the page viewport height VH. When the size of the viewport changes, the sizes of all components in the page change along with the change in the size of the viewport, and thus all components in the page can be automatically scaled. In this way, the size of the components in the page can be dynamically adjusted by changing the size of the viewport, which can reduce the workload of the staff, is beneficial to improving the efficiency of multi-terminal web page development and maintenance, and is beneficial to improving the convenience of page adaptive layout.

[0090] 104. Determine an original adaptive viewport range in pixel units, where the original adaptive viewport range includes an original viewport width range and / or an original viewport height range.

[0091] In the embodiment of the present invention, the original adaptive viewport range is the size range of the target page for displaying all components on the display screen of the terminal device. The unit of the original adaptive viewport range is pixel unit. By determining the original adaptive viewport range in pixel unit, the size range of the page can be determined, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and is conducive to improving the accuracy of page adaptive layout, thereby helping to improve the user experience of using the page.

[0092] In another optional embodiment, determining the original adaptive viewport range in pixel units may include:

[0093] Obtaining the result of the multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, setting the maximum value and the minimum value of the target size type that matches the adaptive scaling method in the size type of the viewport as responsive breakpoints;

[0094] Set the size range of the target page used to display all components according to the adaptive scaling method and the maximum and minimum values ​​of the target size type to determine the original adaptive viewport range in pixels.

[0095] In this optional embodiment, the size type is determined according to the adaptive scaling method, wherein the size type includes a width size type and a height size type. Optionally, when the adaptive scaling method determined is the first adaptive method based on the page width, the size type of the viewport is determined to be the width size type; when the adaptive scaling method determined is the second adaptive method based on the page height, the size type of the viewport is determined to be the height size type. Further, when the size type of the viewport determined is the width size type, the maximum value and minimum value of the target size type in the width size type of the viewport that matches the first adaptive method based on the page width are set as responsive breakpoints. Responsive breakpoints are used to indicate the maximum and minimum values ​​of page adjustment. For example, when the maximum value of the viewport width reaches the value of the responsive breakpoint, the page will automatically make adaptive adjustments. In this way, by setting responsive breakpoints, the display method and layout of web pages can be actively adjusted for different terminal devices or display screens of different sizes, so that web pages can be adjusted on various terminal devices or various display screens. This can reduce the complexity of page adaptation, help reduce page layout disorder and garbled characters, improve the efficiency of multi-terminal web page development and maintenance, and improve the accuracy of determining adaptive scaling methods, which in turn helps improve the user experience of using web pages.

[0096] It can be seen that in this optional embodiment, by combining the results of the multimedia query and the determined adaptive scaling method, the viewport size type and the maximum and minimum values ​​of the target size that matches the adaptive scaling method are set as responsive breakpoints, and then the size range of the target page for displaying all components is set to determine the original adaptive viewport range in pixels. This can reduce the complexity of page adaptation implementation, improve the accuracy of determining the adaptive scaling method, and help improve the efficiency of multi-terminal web page development and maintenance, thereby helping to improve the user experience of using web pages.

[0097] In yet another optional embodiment, the result of the multimedia query includes:

[0098] At least one of a width range and / or a height range of each viewport in a plurality of viewports, a width range and / or a height range of each page in a plurality of pages, and device parameters of a plurality of terminal devices;

[0099] The device parameters of each terminal device include one or more of width, height, type, and resolution.

[0100] In this optional embodiment, the device parameters of each terminal device include the width of the terminal device, the height of the terminal device, the type of the terminal device (such as PC, tablet computer, mobile phone), and the resolution of the terminal device. In this way, by obtaining the results of the multimedia query, the width range and / or height range of the viewport of the target page for displaying all components, the width range and / or height range of the page, and the device parameters of the terminal device can be obtained in all directions, which can improve the accuracy of determining the adaptive scaling method, reduce the complexity of page adaptive implementation, reduce the workload of page development staff, and help improve the efficiency of multi-terminal web page development and maintenance, and thus help improve the user experience of using the web page.

[0101] In yet another optional embodiment, setting the size range of the target page for displaying all components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type may include:

[0102] When the adaptive scaling mode is the first adaptive mode, the maximum value of the width value of the target page for displaying all components is set to the maximum value of the target size type and the minimum value of the width value of the target page is set to the minimum value of the target size type;

[0103] When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page for displaying all components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

[0104] In this optional embodiment, the size type includes a width size type and a height size type. When the adaptive scaling method is the first adaptive method based on the page width, the target size type is determined to be the width size type, the maximum value of the width value of the target page used to display all components is set to the maximum value of the target size type, and the minimum value of the width value of the target page is set to the minimum value of the target size type. In this way, by setting the maximum value and the minimum value of the target page displaying all components to the maximum value and the minimum value of the target size type, the size range of the page can be determined, and then the original adaptive viewport range can be determined, which can reduce the complexity of page adaptation implementation, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and is conducive to improving the accuracy of page adaptive layout, and is conducive to improving the user experience of using web pages.

[0105] 105. Convert the first size of all components into the second size in rem, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

[0106] In the embodiment of the present invention, the unit of the first size of all components is pixel unit, the unit of the original adaptive viewport range is pixel unit, all components in the page are converted from the first size in pixel unit to the second size in rem unit, and the original adaptive viewport range in pixel unit is converted into the target adaptive viewport range in rem unit. In this way, by converting all components and adaptive viewport range in the page into rem unit, the uniformity of the units of all components and adaptive viewport range in the page can be ensured, the complexity of the adaptive layout of the page can be reduced, and the workload of the staff can be reduced, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and can improve the accuracy and convenience of the adaptive layout of the page, which is conducive to improving the user experience of using the web page.

[0107] 106. Generate a CSS style file based on the second size of all components, the root node font size unit, and the target adaptive viewport range.

[0108] In the embodiment of the present invention, the CSS style file (Cascading Style Sheets) is a computer language used to express the file style of Hypertext Markup Language, Extensible Markup Language, etc. The CSS style file provides a style description for Hypertext Markup Language and defines the display mode of the elements therein. The CSS style file can not only modify the web page statically, but also can be used in conjunction with various scripting languages ​​to dynamically layout the various element components in the web page, and can dynamically adjust the page by modifying a small style in the page and updating all page elements related to the CSS style file.

[0109] In an embodiment of the present invention, a CSS style file is generated by using all components of the second size in a page in rem units, the root node font size unit in the page, and the target adaptive viewport range in rem units. The CSS style file can achieve that the sizes of all components in the page are adjusted following the change of the root node font size unit after the change by only changing the root node font size unit. In addition, combined with the target adaptive viewport range in rem units, it can reduce the situation where the page layout is out of control due to the viewport size exceeding the adaptive viewport range (for example, the page is too large or too small), and can make the page present an excellent layout on the display screens of various terminal devices, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and can improve the accuracy and convenience of page adaptive layout, thereby helping to improve the user experience of using web pages.

[0110] In another optional embodiment, converting the first size of all the components into a second size in rem, and converting the original adaptive viewport range into a target adaptive viewport range in rem may include:

[0111] Configure the pxtorem project and use Webpack's PostCss loader combined with the Postcss-pxtorem plug-in to convert the first size of all components into the second size in rem, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

[0112] In this optional embodiment, by configuring the pxtorem project, all components of the first size in the page in pixels can be uniformly converted into components of the second size in rems, and the original adaptive viewport range in pixels can be converted into a target adaptive viewport range in rems, thereby ensuring that the units of all components in the page and the adaptive viewport range are uniformly in rems, ensuring the uniformity of the units of all components in the page, reducing the complexity of the staff in performing page adaptive layout, thereby reducing the staff's workload, improving the efficiency of unit conversion, and improving the accuracy and convenience of page adaptive layout, thereby helping to improve the user experience of using web pages.

[0113] It can be seen that the implementation Figure 1The described method for adaptive page layout based on rem can determine the first size of all components on a reference canvas according to a reference canvas, the unit of the first size of all components is a pixel unit, and according to a predetermined adaptive scaling method and a conversion unit corresponding to the adaptive scaling method, the root node font size unit is set to the conversion unit, and then the original adaptive viewport range in pixel units is determined, the first size of all components is converted into a second size in rem units and all original adaptive viewport ranges are converted into a target adaptive viewport range in rem units, a CSS style file is generated according to the second size of all components, the root node font size unit and the target adaptive viewport range, and page adaptive layout is realized on different terminal devices, so that the page can present an excellent layout form on different terminal devices, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and can improve the accuracy and convenience of page adaptive layout, thereby helping to improve the user experience of using web pages.

[0114] Embodiment 2

[0115] See also Figure 2 , Figure 2 : is a flow chart of a method for page adaptive layout based on rem disclosed in an embodiment of the present invention. Figure 2 The described method of page adaptive layout based on rem can be applied to terminal devices with display screens, such as PC (Personal Computer), notebook computers, tablet computers, mobile phones, etc., and the embodiments of the present invention are not limited thereto. Figure 2 As shown, the page adaptive layout method based on rem may include the following operations:

[0116] 201. Determine a reference canvas, and determine a first size of each component among all components displayed on the reference canvas according to a size of the original design drawing, wherein the unit of the first size of each component is a pixel unit.

[0117] 202. According to a predetermined adaptive scaling method, determine a conversion unit corresponding to the adaptive scaling method, and convert the target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, where the unit of the target value is the conversion unit.

[0118] 203. Build a Sass project using Sass syntax, and determine the conversion relationship between pixel units and conversion units based on the Sass project; the conversion relationship is used to convert the size of any node font obtained into a size with the conversion unit as the unit.

[0119] In the embodiment of the present invention, Sass (full name: Syntactically Awesome Stylesheets) is a language used to develop CSS style files (Cascading Style Sheets), which is an extension of the syntax of CSS style files and can effectively realize dynamic changes of CSS style files.

[0120] In the embodiment of the present invention, a Sass project is built using Sass syntax, and the conversion relationship between pixel units and conversion units can be determined through the Sass project, and the conversion relationship is used to convert the size of any acquired node font into a size in the conversion unit. Further, through the Sass project, a first target value corresponding to converting the target pixel unit into the rem unit based on the reference canvas can be determined, and the unit of the first target value is the rem unit.

[0121] It can be seen that in the embodiment of the present invention, a Sass project can be built through Sass syntax, and the conversion relationship between pixel units and conversion units can be determined according to the Sass project. The conversion relationship is used to convert the size of any acquired node font into a size in conversion units, which can ensure the uniformity of units in the page, reduce the complexity of the staff in performing page adaptive layout, and thus reduce the workload of the staff, and can improve the accuracy and convenience of page adaptive layout, which is beneficial to improving the user experience of using web pages.

[0122] 204. Set the root node font size unit to the conversion unit.

[0123] 205. Determine an original adaptive viewport range in pixel units, where the original adaptive viewport range includes an original viewport width range and / or an original viewport height range.

[0124] 206. Convert the first size of all components into a second size in rem, and convert the original adaptive viewport range into a target adaptive viewport range in rem.

[0125] 207. Generate a CSS style file based on the second size of all components, the root node font size unit, and the target adaptive viewport range.

[0126] In the embodiment of the present invention, for other descriptions of step 201 - step 202 and step 204 - step 207, please refer to the detailed description of step 101 - step 106 in the first embodiment, and the embodiment of the present invention will not be repeated.

[0127] It can be seen that the implementation Figure 2The described method for adaptive page layout based on rem can determine the first size of all components on a reference canvas according to a reference canvas, the unit of the first size of all components is a pixel unit, build a Sass project through Sass syntax according to a predetermined adaptive scaling method and a conversion unit corresponding to the adaptive scaling method, determine the conversion relationship between the pixel unit and the conversion unit, set the root node font size unit to the conversion unit, and then determine the original adaptive viewport range in pixel units, convert the first size of all components into a second size in rem units and convert all the original adaptive viewport ranges into a target adaptive viewport range in rem units, generate a CSS style file according to the second size of all components, the root node font size unit and the target adaptive viewport range, realize page adaptive layout on different terminal devices, enable the page to present an excellent layout form on different terminal devices, reduce the complexity of page adaptive layout, help improve the efficiency of multi-terminal web page development and maintenance, and improve the accuracy and convenience of page adaptive layout, thereby helping to improve the user experience of using web pages.

[0128] Embodiment 3

[0129] See also Figure 3 , Figure 3 is a schematic diagram of a structure of a device for page adaptive layout based on rem disclosed in an embodiment of the present invention. Figure 3 The described apparatus for page adaptive layout based on rem can be applied to terminal devices with display screens, such as PCs (Personal Computers), notebook computers, tablet computers, mobile phones, etc., and the embodiments of the present invention are not limited thereto. Figure 3 The device shown is used to implement the method described in Example 1. Figure 3 As shown, the apparatus for adaptive page layout based on rem may include:

[0130] The determination module 301 is used to determine a reference canvas, and determine a first size of each component among all components displayed on the reference canvas according to the size of the original design drawing, wherein the unit of the first size of each component is a pixel unit.

[0131] The determination module 301 is further configured to determine a conversion unit corresponding to the adaptive scaling method according to a predetermined adaptive scaling method.

[0132] The conversion module 302 is used to convert the target rem unit into a target value corresponding to 100 pixel units based on the conversion unit determined by the determination module 301, where the unit of the target value is the conversion unit.

[0133] The setting module 303 is used to set the root node font size unit as the conversion unit.

[0134] The determination module 301 is further used to determine an original adaptive viewport range in pixel units, where the original adaptive viewport range includes an original viewport width range and / or an original viewport height range.

[0135] The conversion module 302 is further used to convert the first size of all components into a second size in rem, and convert the original adaptive viewport range into a target adaptive viewport range in rem.

[0136] The generating module 304 is used to generate a CSS style file according to the second sizes of all components, the root node font size unit and the target adaptive viewport range.

[0137] It can be seen that the implementation Figure 3 The described device can reduce the complexity of page development and maintenance, is conducive to improving the efficiency of multi-terminal web page development and maintenance, and is conducive to conveniently realizing dynamic page adaptation.

[0138] In an optional embodiment, if Figure 3 As shown, the specific method of determining the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method by the determination module 301 may be:

[0139] When the adaptive scaling mode is the first adaptive mode based on the page width, determining that the conversion unit corresponding to the adaptive scaling mode is the page viewport width VW;

[0140] When the adaptive scaling mode is the second adaptive mode based on the page height, it is determined that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH.

[0141] It can be seen that the implementation Figure 3 The described device can determine the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method, which is beneficial to improving the efficiency of multi-terminal web page development and maintenance, and is beneficial to improving the convenience of page adaptive layout.

[0142] In another optional embodiment, Figure 3 As shown, the specific manner in which the determination module 301 determines the original adaptive viewport range in pixel units may be:

[0143] Obtaining the result of the multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, setting the maximum value and the minimum value of the target size type that matches the adaptive scaling method in the size type of the viewport as responsive breakpoints;

[0144] Set the size range of the target page used to display all components according to the adaptive scaling method and the maximum and minimum values ​​of the target size type to determine the original adaptive viewport range in pixels.

[0145] Optionally, the result of the multimedia query includes at least one of a width range and / or a height range of each viewport in a plurality of viewports, a width range and / or a height range of each page in a plurality of pages, and device parameters of a plurality of terminal devices;

[0146] The device parameters of each terminal device include one or more of width, height, type, and resolution.

[0147] It can be seen that the implementation Figure 3 The described device can reduce the complexity of page adaptation implementation, can reduce the complexity of page adaptation implementation, is conducive to reducing page layout disorder, is conducive to improving the efficiency of multi-terminal web page development and maintenance, is conducive to improving the accuracy of determining the adaptive scaling method, and thus is conducive to improving the user experience of using the web page.

[0148] In yet another optional embodiment, Figure 3 As shown, the specific manner in which the determination module 301 sets the size range of the target page for displaying all components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type may be:

[0149] When the adaptive scaling mode is the first adaptive mode, the maximum value of the width value of the target page for displaying all components is set to the maximum value of the target size type and the minimum value of the width value of the target page is set to the minimum value of the target size type;

[0150] When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page for displaying all components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

[0151] It can be seen that the implementation Figure 3 The described device can uniformly convert all components of a first size in a page in pixels into components of a second size in rems by configuring a pxtorem project, and convert an original adaptive viewport range in pixels into a target adaptive viewport range in rems, thereby ensuring the uniformity of units of all components in the page, reducing the complexity of page adaptive layout for staff, improving the efficiency of unit conversion, and improving the accuracy and convenience of page adaptive layout, thereby helping to improve the user experience of using web pages.

[0152] In yet another optional embodiment, Figure 3 As shown, the specific manner in which the conversion module 302 converts the first size of all components into the second size in rem units, and converts the original adaptive viewport range into the target adaptive viewport range in rem units may be:

[0153] Configure the pxtorem project and use Webpack's PostCss loader combined with the Postcss-pxtorem plug-in to convert the first size of all components into the second size in rem, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

[0154] It can be seen that the implementation Figure 3 The described device can ensure the uniformity of all components in the page and the units of the adaptive viewport range, can reduce the complexity of the page adaptive layout, thereby reducing the workload of the staff, which is conducive to improving the efficiency of multi-terminal web page development and maintenance, and can improve the accuracy and convenience of the page adaptive layout, thereby helping to improve the user experience of using the web page.

[0155] In yet another optional embodiment, Figure 4 As shown, the device may also include:

[0156] A building module 305 is used to build a Sass project using Sass syntax before the setting module 303 sets the root node font size unit to the conversion unit;

[0157] The determination module 301 is further used to determine the conversion relationship between the pixel unit and the conversion unit according to the Sass project constructed by the construction module 305, and the conversion is used to convert the size of any node font obtained into a size in the conversion unit.

[0158] It can be seen that the implementation Figure 4 The described device can build a Sass project through Sass syntax, and determine the conversion relationship between pixel units and conversion units based on the Sass project. The conversion relationship is used to convert the size of any acquired node font into a size in conversion units, which can reduce the complexity of the staff in performing page adaptive layout, thereby reducing the workload of the staff, and can improve the accuracy and convenience of page adaptive layout, which is conducive to improving the user experience of using web pages.

[0159] Embodiment 4

[0160] See also Figure 5 , Figure 5 FIG. 1 is a schematic diagram of the structure of another apparatus for page adaptive layout based on rem disclosed in an embodiment of the present invention. Figure 5As shown, the apparatus for adaptive page layout based on rem may include:

[0161] Memory 401 storing executable program code

[0162] a processor 402 coupled to the memory 401;

[0163] The processor 402 calls the executable program code stored in the memory 401 to execute the steps in the method for page adaptive layout based on rem described in the first embodiment of the present invention or the second embodiment of the present invention.

[0164] Embodiment 5

[0165] An embodiment of the present invention discloses a computer storable medium, which stores computer instructions. When the computer instructions are called, they are used to execute the steps in the method of page adaptive layout based on rem described in embodiment 1 or embodiment 2 of the present invention.

[0166] Embodiment 6

[0167] An embodiment of the present invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute the steps in the method of page adaptive layout based on rem described in embodiment one or embodiment two.

[0168] The device embodiments described above are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, i.e., they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative work.

[0169] Through the specific description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the above technical solution can be essentially or partly contributed to the prior art in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, and the storage medium includes a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable rewritable read-only memory (EEPROM), a compact disc (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.

[0170] Finally, it should be noted that the method and device for page adaptive layout based on rem disclosed in the embodiment of the present invention only disclose the preferred embodiments of the present invention, which are only used to illustrate the technical solution of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for page adaptive layout based on rem, characterized in that: The method comprises: Determine a reference canvas, and determine a first size of each of the components displayed on the reference canvas according to the size of the original design drawing, wherein the unit of the first size of each of the components is a pixel unit; According to a predetermined adaptive scaling method, determining a conversion unit corresponding to the adaptive scaling method, and converting a target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, wherein the unit of the target value is the conversion unit; Set the root node font size unit to the conversion unit; Determine an original adaptive viewport range in pixels, where the original adaptive viewport range includes an original viewport width range and / or an original viewport height range; Convert the first size of all the components into a second size in rem, and convert the original adaptive viewport range into a target adaptive viewport range in rem; Generate a CSS style file according to the second sizes of all the components, the root node font size unit, and the target adaptive viewport range; The step of determining, according to a predetermined adaptive scaling method, a conversion unit corresponding to the adaptive scaling method comprises: When the adaptive scaling mode is a first adaptive mode based on page width, determining that the conversion unit corresponding to the adaptive scaling mode is a page viewport width VW; When the adaptive scaling mode is a second adaptive mode based on the page height, determining that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH; The determining of the original adaptive viewport range using the pixel unit as a unit includes: Obtaining a result of a multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, and setting a maximum value and a minimum value of a target size type in a size type of a viewport that matches the adaptive scaling method as responsive breakpoints; According to the adaptive scaling mode and the maximum and minimum values ​​of the target size type, a size range of the target page for displaying all the components is set to determine an original adaptive viewport range in pixels; The step of setting a size range of a target page for displaying all the components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type includes: When the adaptive scaling mode is the first adaptive mode, the maximum value of the width of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the width of the target page is set to the minimum value of the target size type; When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

2. A page adaptive layout method based on rem according to claim 1, characterized in that: The results of the multimedia query include: At least one of a width range and / or a height range of each viewport in a plurality of viewports, a width range and / or a height range of each page in a plurality of pages, and device parameters of a plurality of terminal devices; The device parameters of each terminal device include one or more of width, height, type, and resolution.

3. The method for page adaptive layout based on rem according to claim 1, characterized in that: Before setting the root node font size unit to the conversion unit, the method further includes: Building a Sass project using Sass syntax, and determining a conversion relationship between the pixel unit and the conversion unit according to the Sass project; The conversion relationship is used to convert the acquired size of any node font into a size with the conversion unit as the unit.

4. The method for page adaptive layout based on rem according to claim 1, characterized in that: The converting the first sizes of all the components into second sizes in rem units, and converting the original adaptive viewport range into a target adaptive viewport range in rem units, comprises: Configure the pxtorem project, and convert the first size of all the components into the second size in rem through the PostCss loader of Webpack combined with the Postcss-pxtorem plug-in, and convert the original adaptive viewport range into the target adaptive viewport range in rem.

5. A device for page adaptive layout based on rem, characterized in that: The device comprises: A determination module, used to determine a reference canvas, and determine a first size of each of all components displayed on the reference canvas according to the size of the original design drawing, wherein the unit of the first size of each component is a pixel unit; The determination module is further used to determine the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method; a conversion module, configured to convert a target rem unit into a target value corresponding to 100 pixel units based on the conversion unit, wherein the unit of the target value is the conversion unit; A setting module, used to set the root node font size unit to the conversion unit; The determination module is further used to determine an original adaptive viewport range in units of pixels, wherein the original adaptive viewport range includes an original viewport width range and / or an original viewport height range; The conversion module is further used to convert the first sizes of all the components into second sizes in rem units, and convert the original adaptive viewport range into a target adaptive viewport range in rem units; A generating module, used for generating a CSS style file according to the second sizes of all the components, the root node font size unit and the target adaptive viewport range; The determination module determines the conversion unit corresponding to the adaptive scaling method according to the predetermined adaptive scaling method in the following manner: When the adaptive scaling mode is a first adaptive mode based on page width, determining that the conversion unit corresponding to the adaptive scaling mode is a page viewport width VW; When the adaptive scaling mode is a second adaptive mode based on the page height, determining that the conversion unit corresponding to the adaptive scaling mode is the page viewport height VH; The method in which the determination module determines the original adaptive viewport range in the pixel unit is specifically as follows: Obtaining a result of a multimedia query, combining the result of the multimedia query and the determined adaptive scaling method, and setting a maximum value and a minimum value of a target size type in a size type of a viewport that matches the adaptive scaling method as responsive breakpoints; According to the adaptive scaling mode and the maximum and minimum values ​​of the target size type, a size range of the target page for displaying all the components is set to determine an original adaptive viewport range in pixels; The determination module sets the size range of the target page for displaying all the components according to the adaptive scaling mode and the maximum and minimum values ​​of the target size type in the following manner: When the adaptive scaling mode is the first adaptive mode, the maximum value of the width of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the width of the target page is set to the minimum value of the target size type; When the adaptive scaling mode is the second adaptive mode, the maximum value of the height of the target page used to display all the components is set to the maximum value of the target size type and the minimum value of the height of the target page is set to the minimum value of the target size type.

6. A device for page adaptive layout based on rem, characterized in that: The device comprises: A memory storing executable program code; a processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the method for page adaptive layout based on rem as described in any one of claims 1 to 4.

7. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method for page adaptive layout based on rem as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Multi-screen adaptive method for mobile terminal front-end development

    CN105912336A

  • Page adaptation method and device, and electronic equipment

    CN106776969A

  • Page adaptation method and device

    CN108241505A

  • Screen adaptation method, device, computer device, and storage medium

    CN109254813A

  • Development method and device of self-adaptive page view, computer equipment and storage medium

    CN109614099A