In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to solve the resize event in js". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the resize event in js".
1. The resize event is triggered when the browser window is adjusted to a new height or width.
2. Triggered on the window, so you can specify the event handler through the JavaScript or the onresize attribute in the element.
Example
/ * Created by taozh on 2017-5-6. * taozh1982@gmail.com * / var EleResize = {_ handleResize: function (e) {var ele = e.target | | e.srcElement; var trigger = ele.__resizeTrigger__; if (trigger) {var handlers = trigger.__z_resizeListeners; if (handlers) {var size = handlers.length For (var I = 0; I < size; iTunes +) {var h = handlers [I]; var handler = h. Handler; var context = h. Context; handler.apply (context, [e]) }}, _ removeHandler: function (ele, handler, context) {var handlers = ele.__z_resizeListeners; if (handlers) {var size = handlers.length; for (var I = 0; I < size; iTunes +) {var h = handlers [I] If (h.handler = = handler & & h.context = = context) {handlers.splice (I, 1); return;}}, _ createResizeTrigger: function (ele) {var obj = document.createElement ('object'); obj.setAttribute (' style', 'display: block Position: absolute; top: 0; left: 0; height: 100%; width: 100%; overflow: hidden;opacity: 0; pointer-events: none; z-index:-1 obj.onload'); obj.onload = EleResize._handleObjectLoad; obj.type = 'text/html'; ele.appendChild (obj); obj.data =' about:blank'; return obj }, _ handleObjectLoad: function (evt) {this.contentDocument.defaultView.__resizeTrigger__ = this.__resizeElement__; this.contentDocument.defaultView.addEventListener ('resize', EleResize._handleResize);}}; if (document.attachEvent) {/ / ie9-10 EleResize.on = function (ele, handler, context) {var handlers = ele.__z_resizeListeners; if (! handlers) {handlers = [] Ele.__z_resizeListeners = handlers; ele.__resizeTrigger__ = ele; ele.attachEvent ('onresize', EleResize._handleResize);} handlers.push ({handler: handler, context: context});}; EleResize.off = function (ele, handler, context) {var handlers = ele.__z_resizeListeners If (handlers) {EleResize._removeHandler (ele, handler, context); if (handlers.length = 0) {ele.detachEvent ('onresize', EleResize._handleResize); delete ele.__z_resizeListeners;} else {EleResize.on = function (ele, handler, context) {var handlers = ele.__z_resizeListeners If (! handlers) {handlers = []; ele.__z_resizeListeners = handlers; if (getComputedStyle (ele, null). Position = = 'static') {ele.style.position =' relative';} var obj = EleResize._createResizeTrigger (ele); ele.__resizeTrigger__ = obj Obj.__resizeElement__ = ele;} handlers.push ({handler: handler, context: context});}; EleResize.off = function (ele, handler, context) {var handlers = ele.__z_resizeListeners; if (handlers) {EleResize._removeHandler (ele, handler, context) If (handlers.length = 0) {var trigger = ele.__resizeTrigger__; if (trigger) {trigger.contentDocument.defaultView.removeEventListener ('resize', EleResize._handleResize); ele.removeChild (trigger); delete ele.__resizeTrigger__ } delete ele.__z_resizeListeners;} thank you for your reading. The above is the content of "how to solve the resize event in js". After the study of this article, I believe you have a deeper understanding of how to solve this problem of the resize event in js, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.