0

https://css-tricks.com/examples/MagicLine/ That's the one I do use, but it requires <script src='//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'></script> But some other scripts requires <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

So what I tried was simply to use them both, but then it crashes.

This is the MagicLine code:

<script>
            $(function() {

    var $el, leftPos, newWidth,
        $mainNav = $("#example-one");

    $mainNav.append("<li id='magic-line'></li>");
    var $magicLine = $("#magic-line");

    $magicLine
        .width($(".current_page_item").width())
        .css("left", $(".current_page_item a").position().left)
        .data("origLeft", $magicLine.position().left)
        .data("origWidth", $magicLine.width());

    $("#example-one li a").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.parent().width();
        $magicLine.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $magicLine.stop().animate({
            left: $magicLine.data("origLeft"),
            width: $magicLine.data("origWidth")
        });    
    });
});
        </script>

And this is the other:

<script>
            $(document).ready(function() {
  $("body").on("click", "a", function() {
    var href = $(this).attr("href");
    if (href.indexOf("#") === 0) {
      $("html, body").animate({
        scrollTop: ($(href).offset().top - 90)
      });
      return false;
    }

  });
});
        </script>

If I use 1.5.2 the last wont work, so if I delete that one it works but the MagicLine. How do I get both to work together?

i5dogdgg
  • 51
  • 1
  • 8
  • 2
    You're not supposed to use two jQuery libraries at the same time. Can't you use the latest version of jQuery 1.x? The main difference between v2.x and v1.x is that the former drops support for legacy browsers. – Terry Jan 19 '16 at 16:00

2 Answers2

0

You're having this problem, because as you say, you have scripts which require different versions of jQuery.

You can run multiple versions of jQuery alongside each other using the noConflict method as described here.

However, the bad news is, you need to edit the scripts you are using - and that can be either impossible or a major headache. In either case, it's a maintenance headache.

Community
  • 1
  • 1
psx
  • 4,040
  • 6
  • 30
  • 59
  • How shall I change it? – i5dogdgg Jan 19 '16 at 16:04
  • @i5dogdgg did you read the page I linked to? It describes the method of using multiple versions of jQuery. You would then need to edit the scripts you are using. – psx Jan 19 '16 at 16:48
0

Just use the newer version of jQuery - 2.1.4 - and then, if needed, also add the jQuery Migrate script to support the code that may rely on an older version of jQuery

sbeliv01
  • 11,550
  • 2
  • 23
  • 24