简体   繁体   English

jQuery在Drupal平台上不起作用,但在本地运行良好

[英]Jquery not working on Drupal platform but works fine locally

I have the following jQuery or a carousel which I have pieced together. 我安装了以下jQuery或轮播。

The jQuery works fine locally - but when uploaded to a Drupal platform the jQuery no longer works. jQuery在本地运行良好-但是当上载到Drupal平台时,jQuery不再起作用。 It will however work when input through the Console. 但是,通过控制台输入时它将起作用。

jQuery: jQuery的:

carousel = (function(){
  // Read necessary elements from the DOM once
  var box = document.querySelector('.carouselbox');
  var next = box.querySelector('.next');
  var prev = box.querySelector('.prev');

  // Define the global counter, the items and the 
  // current item 
  var counter = 0;
  var items = box.querySelectorAll('.content-items li');
  var amount = items.length;
  var current = items[0];

  box.classList.add('active');

  // navigate through the carousel

  function navigate(direction) {

    // hide the old current list item 
    current.classList.remove('current');

    // calculate th new position
    counter = counter + direction;

    // if the previous one was chosen
    // and the counter is less than 0 
    // make the counter the last element,
    // thus looping the carousel
    if (direction === -1 && 
        counter < 0) { 
      counter = amount - 1; 
    }

    // if the next button was clicked and there 
    // is no items element, set the counter 
    // to 0
    if (direction === 1 && 
        !items[counter]) { 
      counter = 0;
    }

    // set new current element 
    // and add CSS class
    current = items[counter];
    current.classList.add('current');
  }

  // add event handlers to buttons
  next.addEventListener('click', function(ev) {
    navigate(1);
  });
  prev.addEventListener('click', function(ev) {
    navigate(-1);
  });

  // show the first element 
  // (when direction is 0 counter doesn't change)
  navigate(0);

})();

从内联中将其删除到自己的js文件-源文件-完美运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 本地托管的Jquery.js无法正常工作,CDN链接可以正常工作 - Locally hosted Jquery.js not working, CDN link works fine 模态不适用于heroku; 但在本地工作正常 - modal not working on heroku; but works fine locally Ajax调用在Google Cloud Platform中返回404-在本地工作正常吗? - Ajax calls return 404 in Google Cloud Platform - works fine locally? 我的JavaScript代码无法在本地运行,但可以在jsfiddle上正常工作,为什么? - My JavaScript code is not working locally, but works fine on jsfiddle, why? jQuery在站点或本地上不起作用,但可以在jsfiddle中使用 - JQuery not working on site or locally but works in jsfiddle jQuery在JSP页面中不起作用,但是javascript正常工作 - JQuery not working in JSP page but javascript works fine jQuery 验证在服务器中不起作用。 在本地工作? 为什么? - jQuery Validation not working in server! Works Locally. Why? jQuery可在jsFiddle中使用,但不适用于Drupal - jQuery works in jsFiddle, but not in Drupal jQuery Datepicker在IE中不起作用,与Firefox和Chrome兼容 - JQuery Datepicker not working in IE, Works fine with Firefox and Chrome jquery .get / .post不工作​​ie 7或8,在ff中工作正常 - jquery .get/.post not working on ie 7 or 8, works fine in ff
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM