Scroll bar control method and device, computer equipment and storage medium

By obtaining and hiding the native scroll bar in the target page, instantiating and installing the custom scroll bar, the problem of the scroll bar style in the third-party component being unable to meet the needs is solved, and a beautiful and specific style scroll bar effect is achieved.

CN118642785APending Publication Date: 2024-09-13SF TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310392127.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-03-13
Filing Date
2023-04-04
Publication Date
2024-09-13

AI Technical Summary

Technical Problem

In third-party components, the native scroll bar style cannot meet the needs, and the custom scroll bar provided by the UI framework cannot be used. As a result, the scroll bar style cannot meet the beautiful or specific style requirements when third-party components need to be referenced.

Method used

In the life cycle mounting completion function of the target page, obtain the element selector information that needs to replace the native scroll bar, hide the native scroll bar, instantiate the custom scroll bar in its container, and listen to the target behavior within the container element to trigger Custom behavior events for custom scroll bars.

Benefits of technology

It is possible to use custom scroll bars to replace native scroll bars in third-party components to meet aesthetic and specific style requirements and improve the display effect of scroll bars.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118642785A
    Figure CN118642785A
Patent Text Reader

Abstract

The invention discloses a scroll bar control method and device, computer equipment and a storage medium, and the method comprises the steps: in a mounting completion function of a target page life cycle, obtaining at least one piece of transmitted element selector information of which a native scroll bar needs to be replaced, according to the element selector information, obtaining a container element where a native scroll bar needing to be replaced in the target page is located, hiding the native scroll bar in the container element, instantiating a user-defined scroll bar, installing the user-defined scroll bar in the container element, monitoring a target behavior triggered in the container element, and storing the monitored target behavior in the target page; triggering a custom behavior event of the custom scroll bar according to the target behavior; according to the embodiment of the invention, the user-defined scroll bar can be used for replacing the original scroll bar in the target page, such as a page comprising a third-party component, so that the scroll bar meeting the requirement can be realized in the page comprising the third-party component, such as a scroll bar with a relatively attractive style can be realized in the third-party component.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of web page development, and in particular to a scroll bar control method, device, computer equipment and storage medium. Background Art

[0002] In the front-end development of web pages, scroll bars are used very frequently. The scroll bar style limitations provided by native browsers often do not meet the requirements, and the scroll bars of major browsers are also incompatible with each other. These problems have caused certain troubles for the front-end development of the web. Therefore, some UI frameworks have emerged, providing scroll bar alternatives, such as the el-scrollBar component in the elementUI framework. The el-scrollBar component solves the scroll bar problem in the front-end development of the web to a certain extent. However, in some cases where third-party components need to be referenced and scroll bars are required in the third-party components, the scroll bar style implemented using the native scroll bar solution provided in the third-party components does not meet the usage requirements, and the scroll bars provided by the UI framework cannot be used in the third-party components, making it a difficult problem to implement scroll bars that meet the requirements in the third-party components. Summary of the invention

[0003] The embodiments of the present application provide a scroll bar control method, apparatus, computer device and storage medium, which can use a custom scroll bar to replace a native scroll bar in a target page, such as a page including a third-party component, so that a scroll bar that meets the requirements can be implemented in the third-party component.

[0004] The present application provides a scroll bar control method, comprising:

[0005] In the mount completion function of the target page life cycle, obtain the passed-in element selector information of at least one element whose native scroll bar needs to be replaced;

[0006] Acquire the container element where the native scroll bar in the target page is located according to the element selector information;

[0007] Hide the native scroll bar in the container element;

[0008] Instantiate a custom scroll bar and install the custom scroll bar in the container element;

[0009] The target behavior triggered in the container element is monitored, and a custom behavior event of the custom scroll bar is triggered according to the target behavior.

[0010] The present application also provides a scroll bar control device, the scroll bar control device comprising:

[0011] A first acquisition module is used to acquire at least one element selector information of which the native scroll bar needs to be replaced in the mount completion function of the target page life cycle;

[0012] A second acquisition module is used to acquire the container element where the native scroll bar is located in the target page according to the element selector information;

[0013] A hiding module, used for hiding the native scroll bar in the container element;

[0014] An instantiation module, used for instantiating a custom scroll bar and installing the custom scroll bar in the container element;

[0015] The event triggering module is used to monitor the target behavior triggered in the container element and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0016] The present application also provides a computer device, comprising: one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the processor to implement the scroll bar control method described in any one of the first aspects.

[0017] The present application also provides a computer-readable storage medium on which a computer program is stored. The computer program is loaded by a processor to execute the steps in the scroll bar control method described in any one of the first aspects.

[0018] The present application obtains at least one element selector information of the native scroll bar that needs to be replaced in the mount completion function of the target page life cycle, and obtains the container element where the native scroll bar to be replaced in the target page is located according to the element selector information. In this way, the native scroll bar to be replaced and the container element where the native scroll bar is located are obtained. It should be noted that the information is obtained in the mount completion function of the target page life cycle. Only after the mount is completed can the corresponding native scroll bar in the target page and the container element where the native scroll bar is located be obtained, and the native scroll bar in the container element is hidden, wherein the native scroll bar is hidden, and the container element is not hidden. Then, a custom scroll bar is instantiated and installed in the container element. In this way, the custom scroll bar and the native scroll bar are in a container element, and the target behavior triggered in the container element is listened to, and the custom behavior event of the custom scroll bar is triggered according to the target behavior. In the embodiment of the present application, the custom scroll bar can be used to replace the native scroll bar in the target page, such as a page including a third-party component, so that a scroll bar that meets the requirements can be implemented in the page including the third-party component, such as a scroll bar with a more beautiful style can be implemented in the third-party component. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 is a flow chart of a scroll bar control method provided in an embodiment of the present application;

[0021] Figure 2 is a schematic diagram of a target page provided in an embodiment of the present application;

[0022] Figure 3 This is a schematic diagram of an embodiment of step 105 in the embodiment of the present application;

[0023] Figure 4 is a schematic structural diagram of an embodiment of a scroll bar control device provided in an embodiment of the present application;

[0024] Figure 5 It is a schematic diagram of the structure of an embodiment of a computer device provided in the embodiments of the present application. DETAILED DESCRIPTION

[0025] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0026] The embodiments of the present application provide a scroll bar control method, device, storage medium and computer equipment. Specifically, the scroll bar control method of the embodiment of the present application can be executed by a computer device, and the scroll bar control device in the embodiment of the present application can be integrated in a computer device. Among them, the computer device can be a terminal or a server device. The terminal can be a smart phone, a tablet computer, a laptop computer, a touch screen, a game console, a personal computer (PC, Personal Computer), a personal digital assistant (Personal Digital Assistant, PDA), an intelligent robot, an intelligent vehicle-mounted terminal device. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms.

[0027] A scroll bar control method, device, computer device and storage medium in the embodiments of the present application can be used in the case where a custom scroll bar in a page cannot be implemented using a UI framework and the native scroll bar does not meet the usage requirements. A scroll bar control method, device, computer device and storage medium provided in the embodiments of the present application will be described in detail below.

[0028] Figure 1 It is a flow chart of a scroll bar control method provided in an embodiment of the present application, and the method includes the following steps.

[0029] 101. In the mount completion function of the target page life cycle, obtain the input selector information of at least one element whose native scroll bar needs to be replaced.

[0030] Among them, the target page needs to implement a scroll bar with a more beautiful or specific style, but the native scroll bar cannot meet the requirements, and the scroll bar cannot be implemented using the el-scrollBar component in the UI framework such as the elementUI framework. For example, the el-scrollBar component cannot change the native scroll bar provided by the third-party component without changing the source code of the third-party component library, and the el-scrollBar component does not support batch application, etc.

[0031] For example, a third-party component needs to be introduced into the target page, and a scroll bar is required in the third-party component. The native scroll bar style of the third-party component is limited. If the limited style is displayed ugly and does not meet the requirements, the scroll bar provided by the UI framework cannot be used in the third-party component because we cannot modify the source code in the third-party component. Correspondingly, the target page refers to the page that includes the third-party component, and the native scroll bar refers to the scroll bar provided by the third-party component. It is necessary to implement a custom scroll bar in the third-party component. Figure 2 As shown, in the target page, there is a table implemented by a third-party component, etc. Since all information cannot be displayed in the table, a scroll bar is required to display other information that is not currently displayed.

[0032] The life cycle of the target page includes the process from the creation to the destruction of the target page. For example, taking the Vue JavaScript framework as an example, the life cycle of Vue is also called the hook function, which is the function triggered from the creation to the destruction of the Vue instance.

[0033] The hook function includes multiple different life cycle functions, such as beforeCreate(), created(), beforeMount(), mounted(), etc. Among them, mounted() means that the template has been rendered into a real Document Object Model (DOM), and the user can see the rendered page.

[0034] In this application, in the mount completion function corresponding to the life cycle of the target page, that is, after the template in the mount completion function is rendered into a real document object model, a newly added interface function is called to obtain the input at least one element selector information for which the native scroll bar needs to be replaced. It should be noted that only after the mount is completed and the template is rendered into a real document object model can the corresponding native scroll bar and the container element in which it is located in the target page be obtained.

[0035] Specifically, an array (selectArr) consisting of selector strings is passed in, and the array is obtained through the interface function. The array stores at least one element selector information of the native scroll bar that needs to be modified / replaced. The array is traversed to obtain at least one element selector information of the native scroll bar that needs to be modified / replaced, such as the identifier of at least one container element of the native scroll bar that needs to be modified / replaced. The container element is the container element where the native scroll bar is located, such as the class or id corresponding to the container element where the native scroll bar is located. Among them, the container element is still an element in the target page, such as div, li, table, section, ul, ol and other elements. Because the element includes the native scroll bar, it is equivalent to a container, so the element is called a container element.

[0036] Among them, one native scroll bar corresponds to one element selector information, and multiple native scroll bars correspond to multiple element selector information. When the array includes multiple element selector information, multiple native scroll bars are replaced accordingly, so that multiple native scroll bars can be automatically replaced at one time, or it can be understood as replacing multiple native scroll bars at the same time. For each native scroll bar that needs to be replaced, steps such as steps 102 to 104 are executed multiple times in a loop to automatically replace multiple native scroll bars, such as automatically updating multiple native scroll bars in a third-party component.

[0037] In some embodiments, at least one configuration item (option) passed in can also be obtained through the interface function, each configuration item corresponds to a configuration, each configuration corresponds to configuration content, and the configuration item is used to configure the style of the custom scroll bar that replaces the native scroll bar, etc. This will also be described below.

[0038] It should be noted that the method in this application is implemented through JavaScript scripts.

[0039] 102. Obtain a container element where the native scroll bar in the target page is located according to the element selector information.

[0040] According to the element selector information, the query selector function of the target page is called, for example, the document.querySelector() function is called to obtain the container element where the native scroll bar of the target page is located. When the document.querySelector() function is called to obtain the container element, one container element can be obtained through one element selector information, and multiple container elements can be obtained through multiple element selector information.

[0041] It should be noted that since the present application is to replace the native scroll bar in a third-party component, it is implemented through a JavaScript script in the mount completion function of the target page life cycle. When the native scroll bar in the existing UI framework or the native scroll bar in the browser is replaced, the corresponding native scroll bar is directly obtained from HTML for replacement. Therefore, the method of determining the conditions for replacing the native scroll bar is different.

[0042] 103. Hide the native scroll bar in the container element.

[0043] After obtaining the container element where the native scroll bar is located, the native scroll bar in the container element is hidden. For example, the native scroll bar may be hidden by setting the CSS of the native scroll bar to display:none.

[0044] It should be noted that in this application, the native scroll bar is directly hidden, rather than the container element of the native scroll bar. It should also be noted that hiding the native scroll bar does not block the events corresponding to the native scroll bar.

[0045] 104, instantiate the custom scroll bar and install the custom scroll bar in the container element.

[0046] The custom scroll bar is implemented by creating multiple basic elements and setting styles of the multiple basic elements in the document object model of the target page.

[0047] For example, div elements and span elements can be created by calling the createElement() function in the document object, where both div elements and span elements are basic elements, and the styles of the div elements and span elements can be set respectively, such as the width, height, color and other styles of each basic element (wherein the sizes involved in the styles, such as width and height, are represented by pixels px), as well as the mutual nesting and arrangement styles between the basic elements, and a custom scroll bar can be drawn according to the div elements and span elements, and the styles of the div elements and span elements, wherein the track of the custom scroll bar is drawn according to the styles of the div elements and div elements, the slider of the custom scroll bar is drawn according to the styles corresponding to the span elements and span elements, and the custom scroll bar is generated according to the plan and the slider.

[0048] Since the custom scroll bar is implemented through the created basic elements and the styles of the basic elements, it can achieve compatibility with different browsers and be applied to different application scenarios, while keeping the style stable. The corresponding styles remain consistent in different browsers and in different application scenarios.

[0049] Before instantiating the custom scroll bar, the scroll bar control method further includes: obtaining the container height of the container element, the container width of the container element, and the visible height of the sub-element display content in the container element, or obtaining the container length of the container element, the container height of the container element, and the visible length of the sub-element display content in the container element. The visible width and visible height can be obtained by calling scrollWidth, scrollHeight, etc. in the document object model, and the container width and container height of the container element can be obtained by calling clientWidth, clientHeight, etc. in the document object model.

[0050] Among them, if the native scroll bar is a scroll bar that slides up and down, then the container height, container width and the visible height of the sub-element display content of the container element are obtained; if the native scroll bar is a scroll bar that slides left and right, then the container length, container height and the visible length of the sub-element display content of the container element are obtained. Among them, the sub-element refers to the element included in the container element, and the sub-element can display content. The visible length or visible height of the displayed content refers to the length or height when the displayed content is naturally displayed when there is no scroll bar. Among them, the container element is the element where the native scroll bar is located, so the container height of the container element and the container length of the container element can be understood as the height and length of the native scroll bar, respectively.

[0051] In the specific implementation, the custom scroll bar class is encapsulated according to the properties of the custom scroll bar and the methods involved in the custom scroll bar. The creation of basic elements and setting the styles of the basic elements, and drawing the custom scroll bar according to the basic elements and the styles of the basic elements are encapsulated in the initialization method of the custom scroll bar, and the initialization method is added to the custom scroll bar class.

[0052] Correspondingly, the steps of instantiating a custom scroll bar include: introducing a custom scroll bar class and calling an initialization method according to the custom scroll bar class; creating multiple basic elements in the document object model of the target page through the initialization method and setting the styles of the multiple basic elements; drawing the custom scroll bar according to the multiple basic elements and the styles of the multiple basic elements; determining the height and width of the track in the custom scroll bar according to the container height, container width and visible height, and determining the height of the slider in the custom scroll bar; or, determining the length and height of the track in the custom scroll bar according to the container length, container height and visible length, and determining the length of the slider in the custom scroll bar.

[0053] In one embodiment, after drawing the custom scroll bar, it is further determined whether the display content of the sub-elements in the container element overflows the container element. If so, the height and width of the track in the custom scroll bar and the height of the slider in the custom scroll bar are further determined, or the length and height of the track in the scroll bar and the length of the slider in the custom scroll bar are defined.

[0054] Wherein, if the custom scroll bar is a scroll bar that slides up and down, it is necessary to determine the height and width of the track in the custom scroll bar, and the height and width of the slider in the custom scroll bar. Correspondingly, the above steps of determining the height and width of the track in the custom scroll bar according to the container height, container width and visible height, and determining the height of the slider in the custom scroll bar include: determining the height of the track in the custom scroll bar according to the container height or the height of the native scroll bar, determining the width of the track in the custom scroll bar according to the container width or the width of the native scroll bar, and determining the height of the slider in the custom scroll bar according to the container height and the visible height. Wherein, the height of the slider can be determined according to the height of the slider = container height / visible height * container height. Wherein, the width of the slider in the custom scroll bar can also be determined according to a preset width, wherein the width of the slider in the custom scroll bar is set to a preset width, for example, the preset width is 5px.

[0055] Wherein, if the custom scroll bar is a scroll bar that slides left and right, it is necessary to determine the length and height of the track in the custom scroll bar, as well as the length and height of the slider in the custom scroll bar. Correspondingly, the above steps of determining the length and height of the track in the custom scroll bar according to the container length, container height and visible length, and determining the length of the slider in the custom scroll bar include: determining the length of the track in the custom scroll bar according to the container length or the length of the native scroll bar, determining the width of the track in the custom scroll bar according to the container width or the width of the native scroll bar, and determining the length of the slider in the custom scroll bar according to the container length and the visible length. Wherein, the length of the slider can be determined according to the length of the slider = container length / visible length * container length. Wherein, the height of the slider in the custom scroll bar can also be determined according to a preset height, wherein the height of the slider is set to a preset height, for example, the preset height is 6px, etc.

[0056] Among them, the step of installing a custom scroll bar in a container element includes: positioning the custom scroll bar to the bottom or right side of the container element through absolute positioning, wherein if the custom scroll bar is a scroll bar that slides up and down, it is positioned to the right side of the container element; if the custom scroll bar is a scroll bar that slides left and right, it is positioned to the bottom of the container element, thus covering the position of the native scroll bar.

[0057] Among them, the custom scroll bar is installed in the container element. It can be seen that the native scroll bar and the custom scroll bar are in the same container element. The native scroll bar is hidden and the custom scroll bar is displayed.

[0058] In one embodiment, if the input also includes at least one configuration item, that is, in the mount completion function, at least one configuration item is also obtained, then after the step of generating the custom scroll bar, it also includes: updating the style of the custom scroll bar according to the configuration content of the configuration item, so as to achieve the custom modification of the style of the custom scroll bar, so that the custom scroll bar can be set according to the style required by the user to meet the personalized needs of the user. It should be noted that the configuration item is also obtained in the mount completion function.

[0059] It should be noted that in this step, the custom scroll bar is instantiated in the mounting completion function through JavaScript script, which is completely different from the prior art method of directly implementing the custom scroll bar by introducing elements / components in HTML and combining CSS style settings.

[0060] 105. Listen to the target behavior triggered in the container element, and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0061] The target behaviors within the container element include behaviors targeting other child elements within the container element, such as the behavior of inserting nodes (or child elements) within the container element, behaviors targeting the container element itself, such as the behavior of scrolling with a wheel, and behaviors targeting custom scroll bars within the container element, such as the behavior of dragging a slider, etc. These target behaviors directly or indirectly affect the custom scroll bar.

[0062] In one embodiment, step 105 includes: monitoring the target behavior triggered in the container element, determining the target element associated with the target behavior; and triggering the custom behavior event of the custom scroll bar in different ways according to different target elements. For example, if the target behavior is a behavior for other child elements, the associated target element is the child element; if the target behavior is a behavior for the container element itself, the associated target element is the container element; if the target behavior is a behavior for the custom scroll bar, the associated target element is the custom scroll bar.

[0063] In some cases, it is also possible to directly determine whether the associated target element is a custom scroll bar to distinguish. Correspondingly, step 105 includes: monitoring the target behavior triggered in the container element, determining whether the target element associated with the target behavior is a custom scroll bar, and triggering the custom behavior event of the custom scroll bar in different ways according to whether the target element is a custom scroll bar.

[0064] Among them, Figure 3 As shown, the above steps of triggering the custom behavior event of the custom scroll bar in different ways according to different target elements, or the above steps of triggering the custom behavior event of the custom scroll bar in different ways according to whether the target element is a custom scroll bar, specifically include the following steps.

[0065] 201, Determine whether the target element is a custom scroll bar.

[0066] When the target element is not a custom scroll bar, steps 202 to 203 are executed; otherwise, when the target element is a custom scroll bar, step 204 is executed.

[0067] 202 , triggering a native behavior event of the native scroll bar according to the target behavior.

[0068] That is, when the target element is not a custom scroll bar, the target behavior triggered in the container element will trigger the native behavior event of the native scroll bar. It should be noted that when the native scroll bar is hidden, the native behavior event of the native scroll bar is not blocked. Therefore, the native behavior event of the native scroll bar is triggered according to the target behavior.

[0069] 203 : When a triggered native behavior event is detected, the native behavior event is intercepted, and a custom behavior event of the custom scroll bar is triggered according to the native behavior event.

[0070] For example, the target behavior includes the behavior of inserting a node (or child element) into a container element, and a native behavior event of a native scroll bar such as a DOMNodeInserted event is triggered according to the target behavior. When the computer device detects the triggered native behavior event, the native behavior event is intercepted, and the native behavior event information, such as the identifier of the native behavior event such as the name, is passed to the custom scroll bar to trigger the custom behavior event of the custom scroll bar, such as calling the custom behavior event and executing the custom behavior event. Correspondingly, the function implemented by the custom behavior event is the same as the function implemented by the native behavior event of the native scroll bar. For example, the custom behavior event of the custom scroll bar includes detecting whether the visible length or visible height of the displayed content in the container element has changed. If it has changed, the length or height of the slider in the custom scroll bar is re-determined, and the corresponding length or height of the displayed slider is updated in real time. The specific method of re-determining the length or height of the slider in the custom scroll bar is the same as above.

[0071] For example, the target behavior includes the scrolling behavior of the wheel within the container element, and the native behavior event of the native scroll bar, such as the scroll event, is triggered according to the target behavior. It should be noted that the native behavior event triggered here is different from the function implemented by the native behavior event in the previous example. When the computer device detects the triggered native behavior event, it intercepts the native behavior event, and passes the native behavior event information, such as the identifier of the native behavior event, such as the name, to the custom scroll bar to trigger the custom behavior event of the custom scroll bar, such as calling the custom behavior event, and executing the custom behavior event. Correspondingly, the function implemented by the custom behavior event is the same as the function implemented by the native behavior event of the native scroll bar. For example, call the scrollLeft or scrollTop of the container element to obtain the scroll distance X corresponding to the target behavior, modify the position of the custom scroll bar slider to X, and update the position of the custom scroll bar slider on the track in real time.

[0072] When the target element is not a custom scroll bar, although the native behavior event of the native scroll bar is triggered according to the target behavior, when the computer device detects the native behavior event call, or detects the triggered native behavior event, the native behavior event is intercepted, and the custom behavior event of the custom scroll bar is triggered according to the native behavior event information to realize the control of the custom scroll bar, that is, the corresponding effect is finally realized on the custom scroll bar, and the effect realized on the custom scroll bar is displayed.

[0073] 204. Trigger a custom behavior event of the custom scroll bar according to the target behavior.

[0074] That is, when the target element itself is a custom scroll bar, the custom form event of the custom scroll bar is triggered directly according to the target behavior.

[0075] For example, when the target behavior is to drag the slider of a custom scroll bar, the custom behavior events such as mouseDown, mouseMove, etc. of the custom scroll bar are triggered, such as calling the custom behavior event, and executing the custom behavior event. For example, to update the drag distance of the slider, such as calculating the position change of the slider, the drag distance of the slider can be obtained by calling the scrollTo() method in the document object model, and the content display position in the container element is updated at the same time, such as updating the distance between the leftmost end of the container element and the leftmost end of the visible content, such as scrollLeft, or updating the distance between the top of the container element and the top of the visible content, such as scrollTop.

[0076] It should be noted that the above-mentioned native behavior events and custom behavior events are just examples, and there are more native behavior events and custom behavior events.

[0077] In the above embodiment, a custom scroll bar can be used to replace the native scroll bar in the target page, such as a page including a third-party component, so that a scroll bar that meets the requirements can be implemented in the page including the third-party component, such as a scroll bar with a more beautiful style can be implemented in the third-party component.

[0078] In one embodiment, if Figure 1 As shown, after obtaining the container element, that is, after step 102, 102a and 102b are also included.

[0079] 102a, determining whether the container element meets the element requirements for adding a custom scroll bar.

[0080] Among them, the element requirements for adding a custom scroll bar include that the element where the custom scroll bar is located must be a block-level element such as div, p, h1~h6, ul, ol, dl, li, dd, table, hr, blockquote, address, table, menu, pre, header, section, aside and footer, etc., and cannot be an inline element such as span, img, a, label, input, abbr (abbreviation), em (emphasis), big, cite (quote), i (italic), q (short quotation), textarea, select, small, sub, sup, strong, u (underline) and button, etc.

[0081] If the container element is a block-level element, it is determined that the requirement is met and step 103 is executed. If the container element is not a block-level element, it is determined that the requirement is not met and step 102b is executed.

[0082] 102b, give a prompt.

[0083] For example, it will prompt that an error has occurred, etc., to help users understand the specific situation.

[0084] Among them, since at least one element selector information of the native scroll bar that needs to be replaced is obtained in the array, the element selector information obtained in the array may be inaccurate. This embodiment further determines whether the container element determined according to the element selector information meets the requirements to avoid exceptions and improve accuracy.

[0085] In all the above embodiments, the scroll bar control method further includes: adding public properties and public methods to each custom scroll bar in the custom scroll bar class. Therefore, after instantiating the custom scroll bar, the public properties and public methods can be exposed, wherein the public properties are called to modify the values ​​of the public properties, or the public methods are called to implement corresponding functions. Among them, the public methods include a destruction method.

[0086] Correspondingly, after instantiating the custom scroll bar, when it is necessary to destroy the custom scroll bar on the target page, call the destruction method of the custom scroll bar, set the display mode of the native scroll bar to display through the destruction method, such as setting the display:initail of the native scroll bar, and remove the custom scroll bar from the document object model of the target page, for example, call the removal method of the document object type such as the removeChild() method to remove the custom scroll bar from the document object model of the target page to destroy the custom scroll bar.

[0087] It should be noted that in the prior art, to destroy the scroll bar, the element where the scroll bar is located can be directly removed from the HTML element, without setting the display mode of the native scroll bar.

[0088] The custom scroll bar in this application is implemented through JavaScript scripts, which can replace multiple native scroll bars in the target page at the same time, and the custom scroll bar is drawn according to the basic elements and the styles corresponding to the basic elements, so that the styles on different browsers or in different application scenarios are unified, without considering compatibility issues, and the custom scroll bar can be customized to meet the various needs of users. This application can use custom scroll bars in third-party components to replace native scroll bars, so that third-party components can achieve scroll bars that meet the needs, such as achieving a more beautiful style, and improve the display effect of the target page.

[0089] All of the above technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described in detail here.

[0090] In order to better implement the scroll bar control method of the present application embodiment, the present application embodiment also provides a scroll bar control device. Figure 4 , Figure 4 The structure diagram of the scroll bar control device provided by the embodiment of the present application is as follows: The scroll bar control device 300 may include a first acquisition module 301 , a second acquisition module 302 , a hiding module 303 , an instantiation module 304 and an event triggering module 305 .

[0091] The first acquisition module 301 is used to acquire at least one element selector information of which the native scroll bar needs to be replaced in the mount completion function of the target page life cycle.

[0092] The second acquisition module 302 is used to acquire the container element where the native scroll bar is located in the target page according to the element selector information.

[0093] The hiding module 303 is used to hide the native scroll bar in the container element.

[0094] The instantiation module 304 is used to instantiate the custom scroll bar and install the custom scroll bar in the container element.

[0095] The event triggering module 305 is used to monitor the target behavior triggered in the container element, and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0096] Among them, the event triggering module 305 is specifically used to monitor the target behavior triggered in the container element, determine the target element associated with the target behavior; use different methods to trigger the custom behavior event of the custom scroll bar according to the difference of the target elements; or, monitor the target behavior triggered in the container element, determine whether the target element associated with the target behavior is a custom scroll bar; use different methods to trigger the custom behavior event of the custom scroll bar according to whether the target element is a scroll bar.

[0097] Wherein, the first acquisition module 301 is also used to obtain the container height of the container element, the container width of the container element and the visible height of the sub-element display content in the container element, or to obtain the container length of the container element, the container height of the container element and the visible length of the sub-element display content in the container element. Correspondingly, the instantiation module 304 is also used to create multiple basic elements in the document object model of the target page and set the styles of the multiple basic elements; draw a custom scroll bar according to the multiple basic elements and the styles; determine the height and width of the track in the custom scroll bar according to the container height, the container width and the visible height, and determine the height of the slider in the custom scroll bar; or determine the length and height of the track in the custom scroll bar according to the container length, the container height and the visible length, and determine the length of the slider in the custom scroll bar.

[0098] The first acquisition module 301 is further used to acquire at least one configuration item of the input custom scroll bar, wherein the at least one configuration item includes configuration content. Correspondingly, the instantiation module 304 is further used to update the style of the custom scroll bar according to the configuration content of the configuration item.

[0099] Among them, Figure 4 As shown, the device further includes a determination module 306 and a reminder module 307. The determination module 306 is used to determine whether the container element meets the element requirement of adding the custom scroll bar, and if so, trigger the hiding module 303, and if not, trigger the reminder module 307.

[0100] like Figure 4 As shown, the device further includes a destruction module 308. The destruction module 308 is used to add a public method for each custom scroll bar in the custom scroll bar class, wherein the public method includes a destruction method; after instantiating the custom scroll bar, the destruction method of the custom scroll bar is called; the display mode of the native scroll bar is set to display through the destruction method, and the removal method of the document object type is called to remove the custom scroll bar from the document object model of the target page, so as to achieve the destruction of the custom scroll bar.

[0101] For the specific implementation of each of the above modules, please refer to the description of the corresponding steps in the method embodiment. For the beneficial effects that can be achieved, please refer to the description of the corresponding steps in the above text, which will not be repeated here.

[0102] An embodiment of the present application also provides a computer device, which integrates any one of the scroll bar control devices provided in the embodiments of the present application, and the computer device includes: one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to have the processor execute the steps of the scroll bar control method described in any one of the above-mentioned scroll bar control method embodiments.

[0103] For example, in the mount completion function of the target page life cycle, obtain at least one element selector information passed in for replacing the native scroll bar; obtain the container element where the native scroll bar in the target page is located according to the element selector information; hide the native scroll bar in the container element; instantiate a custom scroll bar, and install the custom scroll bar in the container element; listen to the target behavior triggered in the container element, and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0104] Specifically, the steps of the scroll bar control method in any embodiment can refer to the contents described above, and the beneficial effects that can be achieved can also refer to the contents described above, which will not be repeated here.

[0105] The present application also provides a computer device that integrates any scroll bar control device provided in the present application. Figure 5 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:

[0106] The computer device may include one or more processing core processors 501, one or more computer-readable storage media memories 502, a power supply 503, an input unit 504 and other components. Those skilled in the art will appreciate that Figure 5 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:

[0107] The processor 501 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 502 and calling data stored in the memory 502, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 501 may include one or more processing cores; preferably, the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 501.

[0108] The memory 502 can be used to store software programs and modules. The processor 501 executes various functional applications and data processing by running the software programs and modules stored in the memory 502. The memory 502 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 502 may also include a memory controller to provide the processor 501 with access to the memory 502.

[0109] The computer device also includes a power supply 503 for supplying power to various components. Preferably, the power supply 503 can be logically connected to the processor 501 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 503 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.

[0110] The computer device may further include an input unit 504, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.

[0111] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 501 in the computer device will load the executable files corresponding to the processes of one or more application programs into the memory 502 according to the following instructions, and the processor 501 will run the application programs stored in the memory 502, thereby realizing various functions, as follows:

[0112] In the mount completion function of the target page life cycle, obtain at least one element selector information passed in for replacing the native scroll bar; obtain the container element where the native scroll bar in the target page is located according to the element selector information; hide the native scroll bar in the container element; instantiate a custom scroll bar and install the custom scroll bar in the container element; listen to the target behavior triggered in the container element, and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0113] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.

[0114] To this end, the embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any scroll bar control method provided in the embodiment of the present application. For example, the computer program can be loaded by the processor to execute the following steps:

[0115] In the mount completion function of the target page life cycle, obtain at least one element selector information passed in for replacing the native scroll bar; obtain the container element where the native scroll bar in the target page is located according to the element selector information; hide the native scroll bar in the container element; instantiate a custom scroll bar and install the custom scroll bar in the container element; listen to the target behavior triggered in the container element, and trigger the custom behavior event of the custom scroll bar according to the target behavior.

[0116] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.

[0117] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.

[0118] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0119] The above is a detailed introduction to a scroll bar control method, device, computer equipment and storage medium provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A scroll bar control method, characterized in that: include: In the mount completion function of the target page life cycle, obtain the passed-in element selector information of at least one element whose native scroll bar needs to be replaced; Acquire the container element where the native scroll bar in the target page is located according to the element selector information; Hide the native scroll bar in the container element; Instantiate a custom scroll bar and install the custom scroll bar in the container element; The target behavior triggered in the container element is monitored, and a custom behavior event of the custom scroll bar is triggered according to the target behavior.

2. The method according to claim 1, characterized in that: The step of monitoring the target behavior triggered in the container element and triggering the custom behavior event of the custom scroll bar according to the target behavior includes: Monitor the target behavior triggered in the container element, and determine the target element associated with the target behavior; Depending on the target element, different methods are used to trigger the custom behavior event of the custom scroll bar; or, Monitor the target behavior triggered in the container element, and determine whether the target element associated with the target behavior is a custom scroll bar; Depending on whether the target element is a scroll bar, a custom behavior event of the custom scroll bar is triggered in different ways.

3. The method according to claim 2, characterized in that The step of triggering the custom behavior event of the custom scroll bar in different ways according to the difference of the target element, or the step of triggering the custom behavior event of the custom scroll bar in different ways according to whether the target element is a scroll bar, comprises: When the element object is not the custom scroll bar, triggering a native behavior event of the native scroll bar according to the target behavior; When a triggered native behavior event is detected, the native behavior event is intercepted, and a custom behavior event of the custom scroll bar is triggered according to the native behavior event; When the element object is the custom scroll bar, a custom behavior event of the custom scroll bar is triggered according to the target behavior.

4. The method according to claim 1, characterized in that The custom scroll bar is implemented by creating multiple basic elements and setting styles of the multiple basic elements in the document object model of the target page. Before the step of instantiating the custom scroll bar, the step further includes: Obtain the container height of the container element, the container width of the container element, and the visible height of the sub-element display content in the container element, or obtain the container length of the container element, the container height of the container element, and the visible length of the sub-element display content in the container element; The step of instantiating the custom scroll bar includes: Creating a plurality of basic elements in the document object model of the target page, and setting styles of the plurality of basic elements; Draw a custom scroll bar according to the multiple basic elements and the style; The height and width of the track in the custom scroll bar and the height of the slider in the custom scroll bar are determined according to the container height, the container width and the visible height; or the length and height of the track in the custom scroll bar and the length of the slider in the custom scroll bar are determined according to the container length, the container height and the visible length.

5. The method according to claim 4, characterized in that In the mount completion function, at least one configuration item of the passed-in custom scroll bar is also obtained, and at least one configuration item includes configuration content; after the step of generating the custom scroll bar, it also includes: updating the style of the custom scroll bar according to the configuration content of the configuration item.

6. The method according to claim 1, characterized in that After getting the container element, it also includes: Determine whether the container element meets the element requirements for adding the custom scroll bar; If it is true, then executing the step of hiding the native scroll bar in the container element; If it does not match, a prompt will be given.

7. The method according to claim 1, characterized in that Before the step to instantiate the custom scrollbar, also include: Adding public methods to each custom scroll bar in the custom scroll bar class, wherein the public methods include a destroy method; After instantiating the custom scroll bar, calling the destroy method of the custom scroll bar; The display mode of the native scroll bar is set to display through the destruction method, and the removal method of the document object type is called to remove the custom scroll bar from the document object model of the target page, so as to achieve the destruction of the custom scroll bar.

8. A scroll bar control device, characterized in that: include: A first acquisition module is used to acquire at least one element selector information of which the native scroll bar needs to be replaced in the mount completion function of the target page life cycle; A second acquisition module is used to acquire the container element where the native scroll bar is located in the target page according to the element selector information; A hiding module, used for hiding the native scroll bar in the container element; An instantiation module, used for instantiating a custom scroll bar and installing the custom scroll bar in the container element; The event triggering module is used to monitor the target behavior triggered in the container element and trigger the custom behavior event of the custom scroll bar according to the target behavior.

9. A computer device, characterized in that: The computer device comprises: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the scroll bar control method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the scroll bar control method according to any one of claims 1 to 7.