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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...