In the readmore.js script, position the "readmore" link within a div instead of outside of it

I have added annotations that vary in length, so I am looking to integrate the readmore.js plugin. To ensure uniform sizing for all annotations (even empty ones), I need to set a minimum height for the div container.

<annotation>
  <div style="width:100%;min-height:70px;overflow:hidden;">
    <p><%= p.annotation %></p>
  </div>
</annotation>

Here is the relevant readmore.js section:

<script>
$('annotation').readmore({
  speed: 75,
  collapsedHeight: 60,
  moreLink: '<a href="#">Show more</a>',
  lessLink: '<a href="#">Show less</a>'
});
</script>

The issue I am facing is when the annotation is long, the "Read more" link appears below the annotation tag instead of inside it, causing content below to shift down by one line.

https://i.sstatic.net/cxfY1.jpg

Is there a way to keep the "read more" link inside the div/annotation without affecting the layout below?

UPDATE: Following the initial response, I realized I need a fixed-height text block and display the "read more" link only if necessary. Thank you!

UPDATE2: I have found a workaround solution to my problem:

 <% if p.annotation.length < 90 %>
                            <div style="height:11px"></div>
                            <% end %>

Answer №1

To include the "read more" link within the annotation tag, you can simply do the following:

(Please note that the "read more" link is enclosed in a span tag with the class name "lnk")

Javascript :

$('annotation div').readmore({
  speed: 75,
  collapsedHeight: 70, // equivalent to the min-height set in the div tag
  moreLink: '<span class="lnk"><a href="#">Show more</a></span>',
  lessLink: '<span class="lnk"><a href="#">Hide</a></span>'
});

CSS :

annotation {
  position: relative;
}

.lnk {
  position: absolute;
  bottom: 0;
  left: 0;
  padding: 10px;
  background-color: white;
}

All annotations now have a consistent height of 70px as shown in the example.

Visit this link for further details and demo.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing an issue in Test Cafe when attempting to click on an invisible link using the Client Function

I need to find a way to click on an invisible button in HTML. I attempted to use ClientFunction, however I encountered an error related to the element. import { Selector,ClientFunction } from 'testcafe'; fixture('Clicking Invisible link&apo ...

Exploring the integration of React with Spotify's Web Playback SDK

There is an exciting new beta feature on Spotify that allows for full song playback in the browser called the Web Playback SDK. The documentation showcases initializing a player immediately using script tags in the main HTML file, requiring an access token ...

The AJAX request becomes stuck in the beforeSend function

$(document).ready(function(){ $('.gbutton').click(function(){ text=$("#textid").val(); $.ajax({ type: "POST", url : "postquery.php", data: "text="+text, beforeSend: function(){ $('# ...

Utilizing ionic-scroll for seamless movement and scrolling of a canvas element

I have set up a canvas element with a large image and I want to enable dragging using ionic-scroll. Following the provided example: <ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px"> <div style="width: 5000px; h ...

Attempting to showcase a pair of unordered lists side by side using the power of flexbox

I am having trouble getting this to display on a single line, no matter what I try. While there may be simpler ways to achieve this without using flexbox, I am eager to learn how to do it using flexbox properties. My desired outcome is to have the first u ...

"Responsive modal with dynamic height based on percentage and a minimum height constraint

My goal is to design a modal dialog that adjusts its height based on a percentage of the browser window height. The modal should maintain a minimum height to ensure it doesn't become too small, and it should dynamically grow, shrink, and re-center as ...

Tips for creating a JSON array for an AJAX post

const myObject = { subjects: [{ area: "Math"}, {area: "English"}] } $.ajax({ type: 'POST', data: {"mydata": JSON.stringify(myObject)}, url: '/tosubjects', dataType: "json", contentType: "application/json", processData: fals ...

Ways to retrieve the identifier of an iframe

document.getElementById(Iframe_id).contentWindow.addEventListener("blur", blurtest, true); This line of code assigns the blur event to an iframe and it is functioning properly. However, when in function blurtest(e) { alert(e.target.id); } An alert ...

What could be causing jQuery to overlook dynamically loaded jQuery Mobile buttons?

While working with a web page that uses jQuery Mobile, I utilized Ajax to load the following HTML content. The key detail is the presence of the onButton class attached to the anchor tag. <a class="onButton ui-btn ui-btn-inline ui-btn-corner-all ui-sha ...

Painting Magic: Exploring the World of Canvas Zoom and Moves

I'm having trouble implementing zoom and pan functionality for this particular canvas drawing. While there are examples available for images, my case is different since I am not working with images. Any tips or suggestions on which libraries to use wo ...

Attempting to modify the audio tag's src attribute with JavaScript

I've been doing online research for the past few weeks and have come across similar solutions to what I'm trying to achieve. However, due to my limited knowledge of javascript, I am struggling to implement them effectively. My goal is to have an ...

Mudblazor - Tap or click within the designated area to trigger the drag and drop functionality

I have incorporated the Mudblazor CSS framework into my Blazor WebAssembly project. Within the drag and drop zone, I have included a button that is supposed to remove each uploaded image. However, when I click on the remove button, it only opens up the fi ...

Acquire the URL using Angular within a local environment

I am currently working on a basic Angular project where I have a JSON file containing some data. [{ "name": "Little Collins", "area": "Bronx", "city": "New York", "coverImage": "https://images.unsplash.com/photo-1576808597967-93bd9aaa6bae?ixlib=rb-1.2.1&a ...

The ESLint tool seems to be struggling to detect the package named "@typescript-eslint/eslint-plugin"

Struggling with getting ESLint to function properly on a new Angular project in VS Code. The error message I keep encountering is about failing to load "@typescript-eslint/eslint-plugin". After spending the past 3 hours troubleshooting, I have searched hig ...

I can't seem to figure out why my container is not centered on the screen, despite setting the margins (left and right) to auto

Hey there, I'm a beginner in programming and currently experimenting with the CSS vertical text slide animator feature. However, when the animation runs smoothly, I noticed that the text appears disproportionate and not properly centered on the screen ...

Tips for implementing a conditional statement within an export default clause

I am completely new to web programming and I'm attempting to create a question-answer feature using Vue.js. export default { // Trying to implement an if statement (if character == "Past", then do these steps) "steps": [ { ...

Unable to save the current light/dark mode preference to local storage

Being a beginner in JavaScript, I am currently working on implementing a simple light mode button for my website which defaults to dark mode. The transition between JS/CSS dark and light modes is seamless, giving the site an appealing look when switching t ...

Unable to decipher the mysterious map of nothingness

I am currently working on a GET method in Node.js. My goal is to fetch data using the GET request and then use the MAP function to gather all the names into an array. However, I encountered the following error: /root/server.js:21 ...

Guidelines for incorporating a table and form in PHP

I recently built a form containing an editable table within it, as shown below: <form action="file.php" id="myform" method="POST"> <input name="inp"> <div class="divclass"> <table id="mytable" name="mytable"> ...

Looping through PHP to set the background color of a map

A basic code I have writes out a 'map' or grid. My goal is to define specific areas - for example, if the value for $i or $j equals 1, it should mark the edge of my 'map' by setting the cell's class to 'edge', which curre ...