Jump to content
Deb

Script conflict?

Recommended Posts

Is it possible to have a Read More Read Less Button with parallax scrolling? Scrolling causes the text to flash.  I am using the following script:

function myFunction() {
  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more"; 
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less"; 
    moreText.style.display = "inline";
  }
}

Above my head!

Share this post


Link to post
Share on other sites

You are forcing the id dots to be  inline at any case.

if dot's style is none make it inline else change it to display none. What does that mean? It's again forcing the div to go inline.

Workout on this if else condition and all will work fine. 

Edited by webtrickshome
typo

Share this post


Link to post
Share on other sites

First off, thank you webtrickshome for taking the time to help me. I tried your suggestion and the flashing went away, but upon reloading the page, the entire section was displayed with a READ LESS button, which doesn't do anything when clicked. Below are the changes I think you intended. Maybe I didn't understand your instructions.

 

function myFunction() {
  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "inline") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more"; 
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less"; 
    moreText.style.display = "inline";
  }
}

When I leave else {dots.style display = "inline";  it showed less  and the SHOW LESS button worked, but the READ MORE button didn't work.  

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×