How to use wp_enqueue_script, style when required

You can create a shortcode:

function load_scripts() {
  wp_enqueue_script('moder');
  wp_enqueue_style('styles');
}

add_shortcode('load_scripts', 'load_scripts');

Then use the shortcode to enqueue the scripts/styles:

[load_scripts]

Or so:

do_shortcode('[load_scripts]');

In terms of running when required, you have to make sure that if you’re loading something that requires these, that you either execute the shortcode or enqueue those scripts/styles, since WordPress won’t automatically know when you need them.

As a side note, wrap the function either in a class or give it a unique name to avoid collisions.

Resources:

Shortcode API

do_shortcode function