Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to share the sidebar with native JS

2025-01-19 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report