Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3793168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:44:03+00:00 2026-05-19T12:44:03+00:00

I’m trying to create a bookmarking feature for my site, so when someone clicks

  • 0

I’m trying to create a bookmarking feature for my site, so when someone clicks on “set bookmark” then they click on a line of text, it will place a bookmark image to the left of that line. (i’ll then save the coor to a cookie, but i can do that without help)

One way I thought about doing it was when the person clicked on a line of text in a paragraph, have it grab the Y coordinate of the place the person clicked, then have that number rounded down to the nearest number divisible by 20. The line height of each paragraphs is 20px, so if you rounded the Y coordinates down, then you would get the top position for that single line inside the paragraph they clicked.

So I think it would go like this: when someone clicks on a line of text in a paragraph, it will get the index of that paragraph, so if it’s the 4th P down the page, the index will be 3, then it will get the Y coordinates of where the user clicked, then round that number down to the nearest number divisible by 20, then place the image to the left of that paragraph with the TOP position of the image being the rounded Y coordinate.

Can anyone help me out with this? I’m kind of lost as you can see:

$('p').click(function(e) {
    var myIndex = $(this).index()
    var myIndexTop = myIndex.top()
    var myIndexLeft = myIndex.left()

    var offset = $(this).offset();
    var y = e.pageY - this.offsetTop;

    $('.bookMarkImg')
        .left(myIndexLeft)
        .top('round down to nearest num thats divisible by 20)
OR?     
    $('.bookMarkImg')
        .css({'left': myIndexLeft, 'top' 'round down to nearest num thats divisible by 20'})
})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:44:03+00:00Added an answer on May 19, 2026 at 12:44 pm

    To round down to the nearest 20:

    y = Math.floor(y / 20) * 20;
    

    Also, .top() and .left() don’t exist: you’ll want:

    • $(this).offset().top and $(this).offset().left for getting the positions
    • .css({left: ..., top: ...}) for setting them

    Another thing is that if you only want one of these bookmark images to be floating around, depending on where you click, then you’ll probably want to put the <img> at the <body> level (at the end), and positioned absolutely, so it is free to move around the entire document. Then, don’t bother subtracting the offset of the paragraph from the y coordinate.

    Sample code:

    $('p').click(function (e) {
        var offset = $(this).offset();
        var top = Math.floor(e.pageY / 20) * 20;
    
        $('.bookMarkImg').css({
            left: offset.left,
            top: top
        }).show();
    });
    

    See a working demo: http://jsfiddle.net/upgBa/

    Note: You may have to consider any padding/margin/border you have on the paragraphs and the body though, which could throw off the calculations (just subtract the “top” portions of these).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.