简体   繁体   English

JS.style.display = “inline” 将在 CSS 中显示为“inline-block”

[英]JS .style.display = “inline” Will display as “inline-block” in CSS

I am writing a code for a "Read more" button, following this example from W3schools .按照W3schools的这个示例,我正在为“阅读更多”按钮编写代码。 The code basically shows and hides the longer text.该代码基本上显示和隐藏较长的文本。

The problem I am facing is with the JS code .style.display = "inline" , but it's displayed as inline-block instead, so it moves my text into next line.我面临的问题是 JS 代码.style.display = "inline" ,但它显示为inline-block ,因此它将我的文本移动到下一行。

 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"; btnText.classList.remove("hide_me"); } else { dots.style.display = "none"; btnText.innerHTML = "Hide"; btnText.classList.add("hide_me"); moreText.style.display = "inline"; jQuery("#more").animate({ maxHeight: '200px', height: '200px' }, ); } if (document.getElementById('vec').style = "inline") { document.getElementById("vec").style.display = "none"; document.getElementById("preberiVec").innerHTML = "Preberi več"; document.getElementById('pikice').style.display = "inline"; document.getElementById("preberiVec").classList.remove('skrij_me'); } }
 #more { display: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <p class="paragraph">Lorem Ipsum is simply dummy text of the printing and typesetting industry. <span id="dots">...</span> <span id="more">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </span> <button onclick="myFunction()" class="gumb_vec" id="myBtn">Read more </button></p>

On the link below, its shown how the text is displayed after it's clicked on read more button:在下面的链接中,它显示了单击阅读更多按钮后文本的显示方式:

在此处输入图像描述

The text is displayed in new line as inline-block , but I would like to have it displayed as inline in the same line as the text before.文本在新行中显示为inline-block ,但我希望将其显示为inline与之前的文本在同一行中。

If anyone have dealt with this problem before, please help me out!如果有人以前处理过这个问题,请帮助我!

Thanks谢谢

It's actually the jQuery animate function that funks with your concept - if you remove it as per the below it works as expected (except without animation).实际上是 jQuery 动画 function 符合您的概念 - 如果您按照下面的方式删除它,它会按预期工作(除了没有动画)。

 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"; btnText.classList.remove("hide_me"); } else { dots.style.display = "none"; btnText.innerHTML = "Hide"; btnText.classList.add("hide_me"); moreText.style.display = "inline"; //jQuery("#more").animate({maxHeight: '200px', height: '200px'},); } }
 #more {display: none;}
 <p class="paragraph">Lorem Ipsum is simply dummy text of the printing and typesetting industry. <span id="dots">...</span> <span id="more">Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. </span> <button onclick="myFunction()" class="gumb_vec" id="myBtn">Read more </button></p>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM