简体   繁体   中英

update the initial screenWidth value without having to refresh the page

i have the following javascript code:

var screenWidth = {"width": document.documentElement.clientWidth}
d3.select(window).on('resize', resize)
function resize() {
    var clientWidth = document.documentElement.clientWidth
    screenWidth["width"] = clientWidth
    return clientWidth
}

i am using the D3.js library

every time the screen size changes, the function resize does return the clientWidth, but what will be the correct way to update the initial screenWidth value without having to refresh the page?

Put this at the end of your body:

(function() {
   // your page initialization code here
   // the DOM will be available here
    var windowWidth = resize();
})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM