- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Javascript not working in my site
Hi there !
I was trying to add some manual functions like the typewriter effect and the testimonial slider in my website through the embdeed coding. The code is ok and I added the javascript in the footer section of the where I wanted to add them. But unfortunately the code for one is working but another is not working.If I put the code(js) for the testimonial slider below the code(js) of typewriter effect (in pages>home>seo setting>Footer code ) then the testimonial slider is working but the typewriter is not. Again if I put the code of typewriter below the testimonial in footer code then The typewiter is working but the testimonial s not. How can I make both of them work . I tried to add it to the assests and they are still not working. Please help adam or Bernadette plssssssssss!!!!
/*for typewriter which is not working*/
<script> var TxtRotate = function(el, toRotate, period) { this.toRotate = toRotate; this.el = el; this.loopNum = 0; this.period = parseInt(period, 10) || 2000; this.txt = ''; this.tick(); this.isDeleting = false; }; TxtRotate.prototype.tick = function() { var i = this.loopNum % this.toRotate.length; var fullTxt = this.toRotate[i]; if (this.isDeleting) { this.txt = fullTxt.substring(0, this.txt.length - 1); } else { this.txt = fullTxt.substring(0, this.txt.length + 1); } this.el.innerHTML = '<span class="wrap">'+this.txt+'</span>'; var that = this; var delta = 300 - Math.random() * 100; if (this.isDeleting) { delta /= 2; } if (!this.isDeleting && this.txt === fullTxt) { delta = this.period; this.isDeleting = true; } else if (this.isDeleting && this.txt === '') { this.isDeleting = false; this.loopNum++; delta = 500; } setTimeout(function() { that.tick(); }, delta); }; window.onload = function() { var elements = document.getElementsByClassName('txt-rotate'); for (var i=0; i<elements.length; i++) { var toRotate = elements[i].getAttribute('data-rotate'); var period = elements[i].getAttribute('data-period'); if (toRotate) { new TxtRotate(elements[i], JSON.parse(toRotate), period); } } // INJECT CSS var css = document.createElement("style"); css.type = "text/css"; css.innerHTML = ".txt-rotate > .wrap { border-right: 0.08em solid #666 }"; document.body.appendChild(css); }; </script>
/*for testimonial slider which is working cus its at the bottom*/ <script> // vars 'use strict' var testim = document.getElementById("testim"), testimDots = Array.prototype.slice.call(document.getElementById("testim-dots").children), testimContent = Array.prototype.slice.call(document.getElementById("testim-content").children), testimLeftArrow = document.getElementById("left-arrow"), testimRightArrow = document.getElementById("right-arrow"), testimSpeed = 4500, currentSlide = 0, currentActive = 0, testimTimer, touchStartPos, touchEndPos, touchPosDiff, ignoreTouch = 30; ; window.onload = function() { // Testim Script function playSlide(slide) { for (var k = 0; k < testimDots.length; k++) { testimContent[k].classList.remove("active"); testimContent[k].classList.remove("inactive"); testimDots[k].classList.remove("active"); } if (slide < 0) { slide = currentSlide = testimContent.length-1; } if (slide > testimContent.length - 1) { slide = currentSlide = 0; } if (currentActive != currentSlide) { testimContent[currentActive].classList.add("inactive"); } testimContent[slide].classList.add("active"); testimDots[slide].classList.add("active"); currentActive = currentSlide; clearTimeout(testimTimer); testimTimer = setTimeout(function() { playSlide(currentSlide += 1); }, testimSpeed) } testimLeftArrow.addEventListener("click", function() { playSlide(currentSlide -= 1); }) testimRightArrow.addEventListener("click", function() { playSlide(currentSlide += 1); }) for (var l = 0; l < testimDots.length; l++) { testimDots[l].addEventListener("click", function() { playSlide(currentSlide = testimDots.indexOf(this)); }) } playSlide(currentSlide); // keyboard shortcuts document.addEventListener("keyup", function(e) { switch (e.keyCode) { case 37: testimLeftArrow.click(); break; case 39: testimRightArrow.click(); break; case 39: testimRightArrow.click(); break; default: break; } }) testim.addEventListener("touchstart", function(e) { touchStartPos = e.changedTouches[0].clientX; }) testim.addEventListener("touchend", function(e) { touchEndPos = e.changedTouches[0].clientX; touchPosDiff = touchStartPos - touchEndPos; console.log(touchPosDiff); console.log(touchStartPos); console.log(touchEndPos); if (touchPosDiff > 0 + ignoreTouch) { testimLeftArrow.click(); } else if (touchPosDiff < 0 - ignoreTouch) { testimRightArrow.click(); } else { return; } }) } </script>
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report

- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
You're probably going to need to compare the code for each widget and see if they share any class or element names. That's usually a good starting point when you have a conflict between two different scripts.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report
- Subscribe to RSS Feed
- Mark Thread as New
- Mark Thread as Read
- Float this Thread for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
but they have different clas and element names. Why is this happening ?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report