antennaio / jquery-bar-rating

jQuery Bar Rating Plugin - minimal, light-weight jQuery ratings.
http://antennaio.github.io/jquery-bar-rating/
MIT License
737 stars 260 forks source link

Init plugin #84

Closed jrean closed 7 years ago

jrean commented 7 years ago

Hi,

Thank you for the awesome work. Wondering, whatever I do, when I load the page I see the dropdown then a few ms later the plugin is initialized and so working.

$(function() {

    $('.square-rating').barrating({
        theme: 'bars-square'
    });

});

My final .js file is loaded at the end of my page like that:

<script src="{{ elixir('js/admin.js') }}" type="text/javascript"></script>

Am I doing something wrong?

Technologeek commented 7 years ago

Avoid waiting for the DOM to get ready to apply your plugin. Just put your plugin's initialization process right after your select field in the HTML body. That should speed it up.

<script>
  $('.square-rating').barrating({
        theme: 'bars-square'
    });
</script>
antennaio commented 7 years ago

Apart from what @Technologeek already suggested, if you're bothered by the select field being visible while your scripts are loading you could also insert the select field into the DOM at the same time as you initialise the plugin... or hide the select field with CSS and show it when your scripts are loaded.