In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to share the sidebar with native JS". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to share the sidebar with native JS.
The results are as follows:
The following is the code implementation, convenient for everyone to copy and paste.
Share the effect # share {position: fixed; width: 100px; height: 200px; background-color: lightblue; left:-100px; top: 100px;} # share span {width: 20px; height: 60px; line-height: 20px Text-align: center; left: 100px; top: 70px; position: absolute; background-color: yellow;} share to / / get element var share = document.getElementById ("share") / / set the event to share share.onmouseover = function () {animate (this, "left", 0);}; share.onmouseout = function () {animate (this, "left",-100);}; / / animate motion function function animate (tag, attr, target) {clearInterval (tag.timer) Tag.timer = setInterval (function () {/ / get the current status of an attribute / / because it has units, it needs to be rounded / / parseInt ("hehe") = > NaN NaN | | 0 / / to deal with the problem of converting auto to NaN, we use short circuit operation. Ensure the robustness of the program var leader = parseInt (getStyle (tag, attr)) | | 0 / / part of the retardation formula is to change the value of step var step = (target-leader) / 10; / / the value will be rounded by offsetLeft. If step is relatively small, it will cause problems that cannot be moved / / change the rounding method step = step > 0 according to the positive or negative number of steps? Math.ceil (step): Math.floor (step); / / ease formula leader = leader + step; / / set to an attribute tag.style [attr] = leader + "px" / / check whether you have reached the specified position if (leader = = target) {clearInterval (tag.timer);}}, 17) } / / used to get a style attribute value of a tag / / function getStyle (tag, attr) {/ / detect which / / box.currentStyle is supported, if there is no value of undefined / / getComputedStyle if the browser does not support it. Equivalent to variable undeclared, error if (tag.currentStyle) {/ / ie supports return tag.currentStyle [attr];} else {/ / standard method return getComputedStyle (tag, null) [attr] }} at this point, I believe you have a deeper understanding of "how to share the sidebar with native JS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.