Script working only on page reload

前端 未结 1 975
半阙折子戏
半阙折子戏 2020-12-20 08:07

I\'m using jQuery to align images on an horizontal view website, but the script only works when I reload the page.

http://joliannelm.steveforest.com/edition/roux-de-

相关标签:
1条回答
  • 2020-12-20 08:31

    This is probably a timing problem: The ready event is fired when the DOM is ready - this can be before the images are loaded. Because you're not giving the images fixed width attributes, you need them to be loaded before you can tell their width.

    This is where the load event is the most appropriate trigger.

    $(window).load(function() {  ... your code here
    

    unlike ready, load will wait for all associated files - images, style sheets, JavaScript files etc.

    0 讨论(0)
提交回复
热议问题