How to use different javascript libraries on the same page?

Asked

Viewed 113 times

0

I’m using a full screen slider on a page I’m creating, this slide uses the following Javascript styles and functions

jQuery 3.2.1:

var TIMEOUT = 6000;


var interval = setInterval(handleNext, TIMEOUT);

function handleNext() {

  var $radios = $('input[class*="slide-radio"]');
  var $activeRadio = $('input[class*="slide-radio"]:checked');

  var currentIndex = $activeRadio.index();
  var radiosLength = $radios.length;

  $radios
    .attr('checked', false);


  if (currentIndex >= radiosLength - 1) {

    $radios
      .first()
      .attr('checked', true);

  } else {

    $activeRadio
      .next('input[class*="slide-radio"]')
      .attr('checked', true);

  }

}

I want to add an off-canvas toogle menu that uses these Javascript styles and functions

jQuery 2.2.4:

$(window).load(function() {
   $(".btn-nav").on("click tap", function() {
     $(".nav-container").toggleClass("showNav hideNav").removeClass("hidden");
     $(this).toggleClass("animated");
   });
 });

The two codes conflict when used together, I have tried to leave only one library and if I withdraw one does not work the other.

I tried the method without conflict and it didn’t work, at least I couldn’t make it work.

I’m sorry I’m naive, I’m new to programming.

Can you help me?

  • Boy, please rephrase your question, I couldn’t understand...

  • Luis, post the snippet of code with the inclusion of libraries in your html and try to simplify your question. Make it more objective.

  • Hi Luis, are you sure you need the older version? Have you tried using only version 3?

  • updated the question with the codes

  • I tried to use only version 3.0 did not work, it works only one of the elements, in case the slider

1 answer

0


Your code is wrong using the method .load (which does not serve that purpose) in:

$(window).load(function() {

You want to create the events when the page is finished loading, so you should use:

$(window).on("load", function() {

Analyzing your code, I didn’t identify any version conflicts, just this quoted error that you’re assuming is jQuery conflict. Make the correction and your code should return to work with any of the versions, but I suggest using the latest, 3.2.1.

  • Thank you, it worked. I get it, there’s no conflict in the code what was wrong was that an event was being called the wrong way, when it was to be called after the page was loaded, thank you again, peace.

  • @Luisrodrigues Cool! I’m glad. If you can, it’s important to mark in the answer. Abs!

  • marked thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.