• Resolved ac1643

    (@ac1643)


    Hi

    I have some jquery code I would like to add to enable smooth scrolling to anchor tags. Couldt you please tell me where I need to put this code in the theme files? It is:

    ——————————–
    {cms_jquery}

    <script type=”text/javascript”>
    jQuery(document).ready(function($) {
    $(“.scroll”).click(function(event) {
    event.preventDefault();
    $(‘html,body’).animate( { scrollTop:$(this.hash).offset().top } , 1000);
    } );
    } );
    </script>
    ——————————–

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Since I guess you don’t plan to update the theme, you can put it in scripts.js (edit: without the <script> tags).

    Though you’ll probably want to use the code that has already been available in the theme for some time now: https://themes.svn.www.ads-software.com/moesia/1.17/js/scripts.js (last block)

    Thread Starter ac1643

    (@ac1643)

    Cheers for the quick response, brilliant.

    2 things:

    1)If i update moesia to a newer version in the future, presumably I would have to add it to js.scripts adain? code again?

    2)With the code above, i think you need to add class=”scroll” along with the href to enable the scrolling mode. With the code in the link you provided, does this require a class definition or does it just make all anchor movements scroll?

    If I was to use your code presumably I also copy it to the scripts.js file?

    Thanks

    1) Yeap. Unless you use a child theme.
    2) You don’t need a class for the code that I linked to, you need one for yours.

    Yeap, same place as it actually is in the theme. Not sure if you noticed, but the file I linked to is the scripts.js from the latest version.

    Thread Starter ac1643

    (@ac1643)

    I’ve added your code in, everything’s working fine.

    Many thanks

    Hey guys, I’m trying to load a popup effect but it won’t work! I’ve checked the code and it works when I run it in netbeans. But it won’t work on my website with Moesia?

    I’ve checked and scripts.js has been loaded on the page where it is supposed to do it’s magic.

    This is my code:

    jQuery(function($) {
      var terms = $('#terms');
      var agree = $('#agree');
      var overlay = $('#overlay');
      var popupBox = $('#popupBox');
    
      terms.click(function() {
        overlay.fadeIn(300);
        popupBox.fadeIn(300);
      });
    
        $('#agree, #overlay').click(function() {
            overlay.fadeOut(300);
            popupBox.fadeOut(300);
        });
    });

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘where to add jquery code’ is closed to new replies.