A method and device for realizing picture barrel layout

The picture barrel layout is realized through the virtual DOM tree and elastic layout style, which solves the problems of complex code and low rendering efficiency in the existing technology, and realizes efficient and simple picture layout rendering.

CN110874251BActive Publication Date: 2024-10-18BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201810996058.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2018-08-29
Publication Date
2024-10-18
Estimated Expiration
2038-08-29

AI Technical Summary

Technical Problem

When implementing image barrel layout in the existing technology, the amount of JavaScript script code is large and the calculation is complex. Image loading failure leads to disordered arrangement. Changes in page size require recalculation of rendering, resulting in low rendering efficiency.

Method used

By creating a virtual DOM tree and constructing a real DOM tree according to its type, rendering pictures combined with elastic layout styles, setting the display width and height, and automatically updating the difference data for efficient rendering.

Benefits of technology

It implements a picture barrel layout with a small amount of code and a simple implementation. Image loading failure does not affect the overall layout. When the page size changes, the row height is automatically adjusted without reloading the image, ensuring efficient rendering of the image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN110874251B_ABST
    Figure CN110874251B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for realizing a barrel layout of an image, and relates to the field of computer technology. A specific implementation of the method includes: obtaining image data, creating an original virtual DOM tree based on the image data; recursively constructing a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree; setting a layout style for a container corresponding to the image, so as to render the image onto a page according to the layout style and the real DOM tree. The method realizes the barrel layout of the image by creating an original virtual DOM tree including virtual DOM nodes, constructing a real DOM tree according to the type of virtual DOM nodes, and then rendering the image onto the page in combination with the layout style, with a small amount of code and simple implementation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a method and device for realizing picture barrel layout. Background Art

[0002] The wooden barrel layout is a popular web page layout structure for displaying image lists. In this layout structure, all images maintain their original aspect ratio, all images in each row have the same height, and each row of images is exactly full (except the last row). The effect of the wooden barrel layout is as follows: Figure 1 shown.

[0003] When implementing the wooden barrel layout with existing technology, hundreds or thousands of lines of JavaScript scripts are required for calculation. The specific implementation principle is: in the process of traversing the image array, according to the height, width and container size of the image, the height, width and aspect ratio of each group of images displayed on the page are dynamically calculated to determine the height and number of images in each row of the image list, and to ensure that the aspect ratio of each image remains constant. Among them, JavaScript is a literal scripting language, and also a dynamic type, weak type, prototype-based language with built-in support types.

[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0005] (1) To ensure that each row of images has the same height and that the aspect ratio of each image is constant, a large amount of calculations must be performed based on the image's height, width, container size, etc., resulting in a large amount of JavaScript code and a complex implementation method.

[0006] (2) If an image fails to load, the width and height of the image displayed on the page cannot be calculated, resulting in missing calculation data for that row and disordered arrangement.

[0007] (3) Since the number of images displayed in each row needs to be calculated based on the width of the container, if the page size changes, that is, the width of the container changes, the image list needs to be recalculated and rendered.

[0008] (4) When the image changes, all DOM nodes need to be directly operated, resulting in low rendering efficiency. Summary of the invention

[0009] In view of this, an embodiment of the present invention provides a method and device for implementing a barrel layout of images. In the embodiment, an original virtual DOM tree including virtual DOM nodes is created, and a real DOM tree is constructed according to the type of the virtual DOM nodes, and then the image is rendered onto the page in combination with the layout style, thereby implementing a barrel layout of the image with a small amount of code and simple implementation.

[0010] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for implementing a picture barrel layout is provided.

[0011] A method for implementing a picture barrel layout according to an embodiment of the present invention includes: obtaining picture data, creating an original virtual DOM tree based on the picture data; recursively constructing a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree; setting a layout style for a container corresponding to the picture, so as to render the picture onto a page according to the layout style and the real DOM tree.

[0012] Optionally, the image data includes image address information, image width information and height information; the types of the virtual DOM nodes include tags, attributes and child nodes; and the creation of the original virtual DOM tree based on the image data includes: creating a div tag, and setting the display width, display height and expansion factor of the image under the style attribute of the div tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information; and creating an img tag, and setting the image address information under the src attribute of the img tag.

[0013] Optionally, the recursively constructing a real DOM tree includes: parsing the virtual DOM node to attribute the virtual DOM node to a tag, an attribute or a child node; creating a corresponding tag of the real DOM tree according to the tag name of the virtual DOM node; adding the attributes of the original virtual DOM tree to the corresponding tags of the real DOM tree; and recursively creating child nodes of the real DOM tree according to the child nodes of the tags and attributes in the original virtual DOM tree, and mounting them on the corresponding tags and attributes of the real DOM tree.

[0014] Optionally, setting a layout style for a container corresponding to the image includes: setting a flexible layout, container attributes and item attributes for the container corresponding to the image; wherein the container attributes include a flex-wrap attribute, and the item attributes include a flex-grow attribute.

[0015] Optionally, the method further includes: when the acquired image data changes or the page size changes, updating the original virtual DOM tree to obtain a new virtual DOM tree; comparing the new virtual DOM tree with the original virtual DOM tree to obtain difference data; and updating the difference data into the real DOM tree to re-render the page.

[0016] To achieve the above objective, according to another aspect of an embodiment of the present invention, a device for implementing a picture barrel layout is provided.

[0017] An apparatus for implementing a barrel layout of an image according to an embodiment of the present invention comprises: a creation module, used to obtain image data, and create an original virtual DOM tree based on the image data; a construction module, used to recursively construct a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree; and a rendering module, used to set a layout style for a container corresponding to the image, so as to render the image onto a page according to the layout style and the real DOM tree.

[0018] Optionally, the image data includes image address information, image width information and height information; the types of the virtual DOM nodes include tags, attributes and child nodes; the creation module is also used to: create a div tag, set the display width, display height and expansion factor of the image under the style attribute of the div tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information; and create an img tag, set the image address information under the src attribute of the img tag.

[0019] Optionally, the construction module is further used to: parse the virtual DOM node to attribute the virtual DOM node to a tag, an attribute or a child node; create a corresponding tag of the real DOM tree according to the tag name of the virtual DOM node; add the attributes of the original virtual DOM tree to the corresponding tags of the real DOM tree; and recursively create child nodes of the real DOM tree according to the child nodes of the tags and attributes in the original virtual DOM tree, and mount them to the corresponding tags and attributes of the real DOM tree.

[0020] Optionally, the rendering module is further used to: set a flexible layout, container attributes and item attributes for the container corresponding to the image; wherein the container attributes include a flex-wrap attribute, and the item attributes include a flex-grow attribute.

[0021] Optionally, the device further includes: an updating module, configured to update the original virtual DOM tree to obtain a new virtual DOM tree when the acquired image data changes or the page size changes; compare the new virtual DOM tree with the original virtual DOM tree to obtain difference data; and update the difference data into the real DOM tree to re-render the page.

[0022] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0023] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a method for realizing a picture barrel layout according to an embodiment of the present invention.

[0024] To achieve the above objective, according to another aspect of the embodiments of the present invention, a computer readable medium is provided.

[0025] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, a method for realizing a picture barrel layout according to an embodiment of the present invention is implemented.

[0026] An embodiment of the above invention has the following advantages or beneficial effects: by creating an original virtual DOM tree including virtual DOM nodes, and constructing a real DOM tree according to the type of virtual DOM nodes, and then rendering the picture to the page in combination with the layout style, the wooden barrel layout of the picture is realized, the amount of code is small, and the implementation is simple; the display width and display height of the picture are set in the virtual DOM node, and when the picture fails to load, the overall layout and the arrangement of other pictures are not affected; by setting container attributes and item attributes for the picture, when the page size changes, there is no need to reload the picture, and the line can be automatically wrapped and the line height can be adjusted; when the data changes, the virtual DOM node is automatically updated, and the difference data between the original virtual DOM node and the new virtual DOM node is updated to the real DOM tree. Subsequently, only the changed part of the real DOM tree needs to be modified, thereby ensuring efficient rendering of the picture.

[0027] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0029] Figure 1 It is a rendering of the realization of the wooden barrel layout in the prior art;

[0030] Figure 2 is a schematic diagram of the main steps of a method for implementing a picture barrel layout according to an embodiment of the present invention;

[0031] Figure 3 is a schematic diagram of the principle of implementing a virtual DOM tree according to an embodiment of the present invention;

[0032] Figure 4 It is a schematic diagram of the main process of a method for implementing a picture barrel layout according to an embodiment of the present invention;

[0033] Figure 5 is a schematic diagram of a page layout effect of a current page size according to an embodiment of the present invention;

[0034] Figure 6 is a schematic diagram of a page layout effect after a page size is changed according to an embodiment of the present invention;

[0035] Figure 7 is a schematic diagram of main modules of a device for implementing picture barrel layout according to an embodiment of the present invention;

[0036] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0037] Fig. 9 It is a schematic diagram of the structure of a computer device suitable for implementing the electronic device of the embodiment of the present invention. DETAILED DESCRIPTION

[0038] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0039] Figure 2 Schematic diagram of the main steps of the method for implementing the picture barrel layout according to an embodiment of the present invention. Figure 2 As shown, the method for implementing the picture barrel layout in the embodiment of the present invention mainly includes the following steps:

[0040] Step S201: Obtain image data, and create an original virtual DOM tree based on the image data. The client obtains image data from the server, and the image data includes image address information, image width information, and image height information. DOM is a document object model (DOM for short), which is a standard programming interface for processing extensible markup language. Virtual DOM is an abstract layer built on the basis of real DOM. The virtual DOM tree includes virtual DOM nodes, and the types of virtual DOM nodes include tags, attributes, or child nodes. After the client obtains the image data, it creates a div tag, and sets the display width, display height, and expansion factor of the image under the style attribute of the div tag; creates an img tag, and sets the image address information under the src attribute of the img tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information in the image information.

[0041] Step S202: Recursively construct a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree. First, parse the virtual DOM nodes to classify the virtual DOM nodes as tags, attributes or child nodes; then create tags of the real DOM tree according to the tag names of the virtual DOM nodes; then add the attributes of the original virtual DOM tree to the corresponding tags of the real DOM tree; finally, recursively create child nodes of the real DOM tree according to the child nodes of the tags and attributes in the original virtual DOM tree, and mount them to the corresponding tags and attributes in the real DOM tree.

[0042] Step S203: Set a layout style for the container corresponding to the image, so as to render the image onto the page according to the layout style and the real DOM tree. The container is the parent element to which an elastic layout needs to be added, and the layout style includes an elastic layout, container attributes, and project attributes. The image is obtained by the browser from the server according to the image address information. This step sets an elastic layout, container attributes, and project attributes for the container corresponding to the image. Among them, the container attributes include the flex-wrap attribute, which is used to achieve automatic line wrap when one axis cannot fit. The project attributes include the flex-grow attribute, and the value of the flex-grow attribute needs to be much larger than the maximum value of the flex-grow attribute of the last row of images in the image list, so as to avoid the situation where the last row still fills the entire row when the number of images is small, resulting in the image being too flat and long. After constructing the real DOM tree and setting the layout style, the wooden barrel layout of web page images can be achieved by letting the browser draw it to the page.

[0043] Figure 3 Schematic diagram of the principle of implementing a virtual DOM tree according to an embodiment of the present invention. Figure 3 As shown, React maintains a virtual DOM tree in memory and reads or writes the virtual DOM tree. When the image data changes, React automatically updates the virtual DOM tree, then compares the new virtual DOM tree with the old virtual DOM, finds the changed part (i.e., diff), puts the diff into a queue (i.e., patch), and finally updates these diffs to the real DOM tree in batches. Virtual DOM has batch processing and efficient diff algorithms, because virtual DOM can ensure that only actual DOM operations are performed on the parts that really change on the page, so the entire page can be refreshed at any time without worrying about performance issues. This solution takes advantage of the characteristics and principles of virtual DOM, only changes the changed parts, and ensures efficient rendering of the image list. Among them, React is a JavaScript library for building user interfaces.

[0044] Figure 4FIG. 1 is a schematic diagram of the main flow of a method for implementing a picture barrel layout according to an embodiment of the present invention. Figure 4 As shown, the method for implementing the picture barrel layout in the embodiment of the present invention mainly includes the following steps:

[0045] Step S401: Send a request to the server to obtain the image ID of the image, receive the image data returned by the server, and create an original virtual DOM tree based on the image data. The client sends a request to the server to obtain the image ID of the image; after receiving the image ID, the server feeds back the image data corresponding to the image ID to the client. The image data includes the image address information, the width information and the height information of the image.

[0046] The original virtual DOM tree includes multiple virtual DOM nodes, the types of the virtual DOM nodes include tags, attributes and child nodes, and the tags include div tags and img tags; the attributes of the div tag include style attributes, which are used to set the style of the DOM node and may include any one or more of the following attributes: color, background color, font size, width, flex-grow (expansion factor) and height; the attributes of the img tag include src attributes and alt attributes, the src attribute is used to identify the image address information (i.e., the URL of the image), and the alt attribute is used to identify the replacement text when the image cannot be displayed. Among them, URL is a uniform resource locator, and its full English name is Uniform Resource Locator. Since the speed of operating JS (JavaScript) objects in memory is significantly faster than the speed of operating real DOM nodes, JS objects can be used to create virtual DOM nodes so that the updates of the page can be fully reflected in the JS object.

[0047] In the embodiment, the implementation process of creating the original virtual DOM tree is: using JS language to create a div tag and add a style attribute to the div tag; then creating an img tag and setting the image address information for the img tag, thus obtaining the original virtual DOM node. The specific implementation code can be:

[0048]

[0049] In the embodiment, the value of the height attribute in the style attribute (i.e., the display height) is set to automatic (auto). The value of the width attribute is set to a predetermined aspect ratio, and the specific aspect ratio can be adjusted at will. The value of the width attribute (i.e., the display width) determines how many pictures are in a row. The px in the width attribute is pixel, which is the unit of display width. The value of the flex-grow attribute is set to a predetermined aspect ratio, and the specific aspect ratio can be adjusted at will. The flex-grow attribute determines how to allocate the remaining space when the parent element has remaining space in the space allocation direction. Its value is a weight, which defaults to 0, and the remaining space will be allocated according to this weight. This solution implements the barrel layout of the picture list by setting the flex-grow attribute, avoiding the use of JavaScript scripts to arrange pictures after a lot of calculations.

[0050] Step S402: Recursively construct a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree. First, parse the virtual DOM nodes to determine which virtual DOM nodes belong to tags, which belong to attributes, and which belong to child nodes, and select the method of creating real DOM nodes in the real DOM tree and the method of adding attributes. Then, according to the tag name of the virtual DOM node, call the createElement method to create the corresponding tag of the real DOM tree; add all the attributes of each tag in the original virtual DOM tree to the corresponding tag of the real DOM tree; if the tags and attributes of the original virtual DOM tree have child nodes, recursively call the createElement method to create child nodes of the real DOM tree, and mount them to the corresponding tags and attributes in the real DOM tree through the appendChild method. In the process of building the real DOM tree, the browser will obtain the image corresponding to the image address information from the server.

[0051] Step S403: According to user needs, set the layout style for the container corresponding to the image. The container is the parent element to which the flexible layout (Flex layout) needs to be added. The container has two axes by default: the horizontal main axis and the vertical cross axis. The item refers to each child element in the container. The layout style includes flexible layout, container attributes and item attributes. After setting the flexible layout for the container, the container content can be displayed using the flexible layout instead of following the display method of the conventional document flow. The implementation statement for setting the flexible layout is: display:flex.

[0052] There are 6 container attributes, namely flex-direction attribute, flex-wrap attribute, flex-flow attribute, justify-content attribute, align-items attribute and align-content attribute. Among them, the flex-direction attribute is used to define the direction of the main axis; the flex-wrap attribute is used to define how to wrap if one axis line cannot be arranged; the flex-flow attribute is a short form of flex-direction and flex-wrap, and the default value is row nowrap, row indicates that the main axis is in the horizontal direction and the starting point is at the left end, and nowrap means no line break; the justify-content attribute is used to define the alignment of the item on the main axis; the align-items attribute is used to define how the item is aligned on the cross axis; the align-content attribute is used to define the alignment of multiple axes. If the item has only one axis line, this attribute does not work. In the embodiment, the flex-wrap attribute is set to wrap, and the corresponding statement is flex-wrap:wrap, which realizes automatic line break if one axis line cannot be arranged, and the first line is at the top of the container.

[0053] There are also 6 item attributes, namely order attribute, flex-grow attribute, flex-basis attribute, flex attribute and align-self attribute. Among them, the order attribute is used to define the order of items. The smaller the value, the closer it is arranged. The default value is 0; the flex-grow attribute is used to define the magnification ratio of the item. The default value is 0, that is, if there is remaining space, it will not be enlarged; the flex-shrink attribute is used to define the reduction ratio of the item. The default value is 1, that is, if there is insufficient space, the item will be reduced; the flex-basis attribute is used to define the main axis space occupied by the item (if the main axis is horizontal, setting this attribute is equivalent to setting the width of the item, and the original width will be invalid); the flex attribute is an abbreviation of flex-grow, flex-shrink and flex-basis. The default value is 0 1auto, and the latter two attributes are optional; the align-self attribute is used to define the arrangement of a single item on the cross axis, which can override the align-items attribute on the container. In the embodiment, the flex-grow property of the after pseudo-class of the container is set to avoid the situation where the last row of pictures is too long and the whole row is still filled when there are few pictures in the last row. The implementation statement can be: flex-grow:999999999. The after pseudo-class is used to insert another element at the end of the container to play a placeholder role.

[0054] Step S404: Render the image onto the page according to the layout style and the real DOM tree. The layout style and the real DOM tree are merged to obtain a rendering tree, wherein the rendering tree includes nodes required for rendering the page (i.e., the image obtained according to the image address information); the position and size of each node in the rendering tree are calculated to render each node of the rendering tree onto the page of the browser.

[0055] Step S405: When the acquired image data changes or the page size changes, the original virtual DOM tree is updated to obtain a new virtual DOM tree. The acquired image data changes, for example, compared with the image data acquired in the last request, the image address information of the fifth image has changed, then the corresponding virtual DOM node in the virtual DOM tree created or updated when the image data was acquired last time is updated to obtain a new virtual DOM tree. For another example, the last request was for three images, and this request is for two images. The page size changes, for example, the browser page changes from 2048×1153 to 1280×1024.

[0056] Step S406: Compare the new virtual DOM tree with the original virtual DOM tree to obtain difference data. The difference types between the two virtual DOM trees include tag deletion, tag type change, attribute change, and moving, adding, and deleting child nodes. The tag type change, for example, changes from a div tag to a P tag; the attribute change, for example, changes from an item1 attribute to an item4 attribute. The difference between the two virtual DOM trees can be compared by calling the diff function. The diff function includes the diffProps function, the dfsWalk function, and the diffChildren function. The diffProps function is used to compare the difference between two attributes, the dfsWalk function is used to traverse the two virtual DOM trees in depth first, and the diffChildren function is used to compare the difference between child nodes. When comparing differences, only tags, attributes, or child nodes at the same level are compared.

[0057] Step S407: Update the difference data to the real DOM tree to re-render the page. According to the different difference types in the difference data, call the applyPatches function to update the real DOM tree. According to the layout style and the updated real DOM tree, render the changed pictures onto the page.

[0058] Figure 5 is a schematic diagram of a page layout effect of a current page size according to an embodiment of the present invention, Figure 6 It is a schematic diagram of the page layout effect after the page size changes according to an embodiment of the present invention. Figure 5This is the page layout effect of the picture when the page size is 2048×1153; Figure 6 The page layout effect of the picture after changing the page size from 2048×1153 to 1280×1024. Figure 5 and Figure 6 It can be seen that when the page size changes, the number of images displayed in each row, the display height of each row of images, and the length of each image will be automatically adjusted. This is because the layout style is set for the images in advance. When the page size changes, the client does not need to reload the images. When a row of images is full, it can automatically wrap and adjust the row height, and then re-render to the page to achieve the above effect.

[0059] It can be seen from the method for realizing the barrel layout of pictures in the embodiment of the present invention that by creating an original virtual DOM tree including virtual DOM nodes, and constructing a real DOM tree according to the type of virtual DOM nodes, and then rendering the pictures to the page in combination with the layout style, the barrel layout of the pictures is realized, the amount of code is small, and the implementation is simple; the display width and display height of the pictures are set in the virtual DOM node, and when the picture loading fails, the overall layout and the arrangement of other pictures are not affected; by setting container attributes and project attributes for the pictures, when the page size changes, there is no need to reload the pictures, and the lines can be automatically wrapped and the line height can be adjusted; when the data changes, the virtual DOM node is automatically updated, and the difference data between the original virtual DOM node and the new virtual DOM node is updated to the real DOM tree, and only the changed part of the real DOM tree needs to be modified later, thereby ensuring efficient rendering of the pictures.

[0060] Figure 7 Schematic diagram of the main modules of the apparatus for implementing the picture barrel layout according to an embodiment of the present invention. Figure 7 As shown, the device 700 for implementing the picture barrel layout according to the embodiment of the present invention mainly includes:

[0061] The creation module 701 is used to obtain image data and create an original virtual DOM tree based on the image data. The client obtains the image data from the server, and the image data includes image address information, image width information and height information. The virtual DOM tree includes virtual DOM nodes, and the types of virtual DOM nodes include tags, attributes or child nodes. After the client obtains the image data, it creates a div tag and sets the display width, display height and expansion factor of the image under the style attribute of the div tag; creates an img tag and sets the image address information under the src attribute of the img tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information.

[0062] The construction module 702 is used to recursively construct a real DOM tree according to the type of the virtual DOM node in the original virtual DOM tree. The virtual DOM node is parsed to classify the virtual DOM node as a tag, attribute or child node; then the tag of the real DOM tree is created according to the tag name of the virtual DOM node; then the attribute of the original virtual DOM tree is added to the corresponding tag of the real DOM tree; finally, the child nodes of the real DOM tree are recursively created according to the child nodes of the tags and attributes in the original virtual DOM tree, and mounted to the corresponding tags and attributes in the real DOM tree.

[0063] Rendering module 703 is used to set a layout style for the container corresponding to the picture, so as to render the picture onto the page according to the layout style and the real DOM tree. The container is a parent element to which an elastic layout needs to be added, and the layout style includes an elastic layout, container attributes, and project attributes. This step sets an elastic layout, container attributes, and project attributes for the container corresponding to the picture. Among them, the container attributes include a flex-wrap attribute, which is used to achieve automatic line breaks when one axis cannot fit. The project attributes include a flex-grow attribute, and the value of the flex-grow attribute needs to be much larger than the maximum value of the flex-grow attribute of the last row of pictures in the picture list, so as to avoid the situation where the last row of pictures still fills the entire row when the number of pictures is small, resulting in the picture being too flat and long. After constructing the real DOM tree and setting the layout style, the browser obtains the corresponding picture from the server according to the picture address information, and then renders the picture to the page to achieve the wooden barrel layout of the web page picture.

[0064] In addition, the apparatus 700 for implementing the picture barrel layout according to the embodiment of the present invention may further include: an update module ( Figure 7 ), this module is used to update the original virtual DOM tree to obtain a new virtual DOM tree when the acquired image data changes or the page size changes; compare the new virtual DOM tree with the original virtual DOM tree to obtain difference data; and update the difference data to the real DOM tree to re-render the page.

[0065] From the above description, it can be seen that by creating an original virtual DOM tree including virtual DOM nodes, and constructing a real DOM tree according to the type of virtual DOM nodes, and then rendering the image to the page in combination with the layout style, the barrel layout of the image is realized, with less code and simple implementation; the display width and display height of the image are set in the virtual DOM node, and when the image fails to load, it does not affect the overall layout and the arrangement of other images; by setting container attributes and item attributes for the image, when the page size changes, there is no need to reload the image, and it can automatically wrap and adjust the row height; when the data changes, the virtual DOM node is automatically updated, and the difference data between the original virtual DOM node and the new virtual DOM node is updated to the real DOM tree. Subsequently, only the changed part of the real DOM tree needs to be modified, thereby ensuring efficient rendering of the image.

[0066] Figure 8 An exemplary system architecture 800 is shown to which a method for implementing a picture bucket layout or an apparatus for implementing a picture bucket layout according to an embodiment of the present invention can be applied.

[0067] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0068] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0069] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0070] The server 805 may be a server that provides various services, such as a background management server that provides support for acquisition requests including image identifiers sent by users using the terminal devices 801, 802, and 803. The background management server may analyze and process the received acquisition requests, and feed back the processing results (such as image data corresponding to the icon identifier) ​​to the terminal device.

[0071] It should be noted that the method for implementing the picture barrel layout provided in the embodiment of the present application is generally executed by the terminal devices 801 , 802 , and 803 . Accordingly, the device for implementing the picture barrel layout is generally arranged in the terminal devices 801 , 802 , and 803 .

[0072] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0073] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.

[0074] The electronic device of the present invention comprises: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement a method for realizing a picture barrel layout according to an embodiment of the present invention.

[0075] The computer-readable medium of the present invention stores a computer program thereon, and when the program is executed by a processor, a method for realizing a picture barrel layout according to an embodiment of the present invention is implemented.

[0076] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 suitable for implementing an electronic device of an embodiment of the present invention. Fig. 9 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0077] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the computer system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0078] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.

[0079] In particular, according to the embodiments disclosed in the present invention, the process described in the main step diagram above can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the main step diagram. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.

[0080] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0081] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0082] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a creation module, a construction module and a rendering module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the creation module may also be described as "a module for obtaining image data and creating an original virtual DOM tree based on the image data".

[0083] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: obtaining image data, creating an original virtual DOM tree based on the image data; recursively constructing a real DOM tree according to the type of virtual DOM nodes in the original virtual DOM tree; setting a layout style for the container corresponding to the image, so as to render the image onto the page according to the layout style and the real DOM tree.

[0084] From the above description, it can be seen that by creating an original virtual DOM tree including virtual DOM nodes, and constructing a real DOM tree according to the type of virtual DOM nodes, and then rendering the image to the page in combination with the layout style, the barrel layout of the image is realized, with less code and simple implementation; the display width and display height of the image are set in the virtual DOM node, and when the image fails to load, it does not affect the overall layout and the arrangement of other images; by setting container attributes and item attributes for the image, when the page size changes, there is no need to reload the image, and it can automatically wrap and adjust the row height; when the data changes, the virtual DOM node is automatically updated, and the difference data between the original virtual DOM node and the new virtual DOM node is updated to the real DOM tree. Subsequently, only the changed part of the real DOM tree needs to be modified, thereby ensuring efficient rendering of the image.

[0085] The above product can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not described in detail in this embodiment, please refer to the method provided by the embodiment of the present invention.

[0086] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for realizing picture barrel layout, characterized in that: include: Obtain image data, and create an original virtual DOM tree based on the image data; Recursively construct a real DOM tree according to the types of virtual DOM nodes in the original virtual DOM tree; Setting a layout style for a container corresponding to the image, so as to render the image onto a page according to the layout style and the real DOM tree, wherein the container is a parent element to which an elastic layout needs to be added, and the layout style includes an elastic layout, container attributes, and item attributes; The image data includes image address information, image width information and image height information; the types of the virtual DOM nodes include tags, attributes and child nodes; The creating an original virtual DOM tree based on the image data includes: Create a div tag, and set the display width, display height and expansion factor of the image under the style attribute of the div tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information; Create an img tag, and set the image address information under the src attribute of the img tag; Rendering the image onto the page according to the layout style and the real DOM tree includes: Merging the layout style and the real DOM tree to obtain a rendering tree, wherein the rendering tree includes nodes required for rendering the page; calculating the position and size of each node in the rendering tree to render each node of the rendering tree onto the page, wherein the node represents a picture obtained according to the picture address information; The recursive construction of the real DOM tree includes: Parsing the virtual DOM node to attribute the virtual DOM node to a tag, an attribute or a child node; Create a tag of a real DOM tree according to the tag name of the virtual DOM node; Add the attributes of the original virtual DOM tree to the corresponding tags of the real DOM tree; According to the child nodes of the tags and attributes in the original virtual DOM tree, the child nodes of the real DOM tree are recursively created and mounted on the tags and attributes corresponding to the real DOM tree.

2. The method according to claim 1, characterized in that The container attributes include a flex-wrap attribute, and the item attributes include a flex-grow attribute.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: When the acquired image data changes or the page size changes, the original virtual DOM tree is updated to obtain a new virtual DOM tree; Compare the new virtual DOM tree with the original virtual DOM tree to obtain difference data; The difference data is updated into the real DOM tree to re-render the page.

4. A device for realizing the layout of picture barrels, characterized in that: include: A creation module, used to obtain image data and create an original virtual DOM tree based on the image data; A construction module, used for recursively constructing a real DOM tree according to the types of virtual DOM nodes in the original virtual DOM tree; A rendering module, used to set a layout style for a container corresponding to the image, so as to render the image onto a page according to the layout style and the real DOM tree, wherein the container is a parent element to which an elastic layout needs to be added, and the layout style includes an elastic layout, container attributes, and item attributes; The image data includes image address information, image width information and image height information; the types of the virtual DOM nodes include tags, attributes and child nodes; The creation module is also used to: Create a div tag, and set the display width, display height and expansion factor of the image under the style attribute of the div tag; wherein the values ​​of the display width and expansion factor are set according to the width information and height information; and Create an img tag, and set the image address information under the src attribute of the img tag; The building blocks are also used to: Parsing the virtual DOM node to attribute the virtual DOM node to a tag, an attribute or a child node; Create a tag of a real DOM tree according to the tag name of the virtual DOM node; Adding the attributes of the original virtual DOM tree to the corresponding tags of the real DOM tree, wherein the nodes represent the pictures obtained according to the picture address information; and According to the child nodes of the tags and attributes in the original virtual DOM tree, the child nodes of the real DOM tree are recursively created and mounted on the tags and attributes corresponding to the real DOM tree.

5. The device according to claim 4, characterized in that The container attributes include a flex-wrap attribute, and the item attributes include a flex-grow attribute.

6. The device according to claim 4 or 5, characterized in that The device also includes: an updating module for When the acquired image data changes or the page size changes, the original virtual DOM tree is updated to obtain a new virtual DOM tree; Compare the new virtual DOM tree with the original virtual DOM tree to obtain difference data; and The difference data is updated into the real DOM tree to re-render the page.

7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 3.

8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Method for rendering and incrementally updating webpages

    CN105630902A

  • Interface layout interference detection

    US20180113858A1