Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a scroll back to top button #216

Conversation

SamarthShukla17
Copy link

@SamarthShukla17 SamarthShukla17 commented Mar 15, 2024

Fixes

Description

This Fix, resolves the issue of adding a scroll back to top button on the cc resource archive page.

Screenshots

image

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Created a scroll back to top button.
@SamarthShukla17 SamarthShukla17 requested a review from a team as a code owner March 15, 2024 06:46
@SamarthShukla17 SamarthShukla17 requested review from TimidRobot and annatuma and removed request for a team March 15, 2024 06:46
@possumbilities
Copy link
Contributor

Hi @SamarthShukla17 thanks for this contribution! I think the approach here needs a little adjustment.

For the actual button the more appropriate element would be an anchor <a>, rather than a <button>, that targets an id set on an existing element at the top of the page, or introducing a span element with that target id as a proper target. That would completely remove the need to have any javascript make the scroll to top behavior occur since an anchor can jump between set ids on a page already.

As for making the button appear after the user has scrolled a certain degree down the page, the amount of scroll needs to be long enough that the button would only appear on longer pages, and any javascript doing this would need to be within a separate .js file, whether that's one that's already there, or a new one. Moving it into a file may also require a slight rewrite of the logic, but it'll keep the logic in a more appropriate location.

@SamarthShukla17

This comment was marked as outdated.

@SamarthShukla17 SamarthShukla17 marked this pull request as draft March 16, 2024 03:33
I have created a scroll back to top button and an additional js for the same has been created.
@SamarthShukla17
Copy link
Author

@possumbilities I have created it using anchor tag, but could not create a new .js file as while running it could not initialize the file correctly. I'm updating the PR so review it once, and provide your feedback.❤️

Made the code more efficient.
@SamarthShukla17 SamarthShukla17 marked this pull request as ready for review March 16, 2024 04:44
@SamarthShukla17
Copy link
Author

And, now the scroll to top button only appears after scrolling 1000px.

@SamarthShukla17 SamarthShukla17 marked this pull request as draft March 19, 2024 10:43
Updated the JS code for the scroll to top to make it more effective.
@SamarthShukla17 SamarthShukla17 marked this pull request as ready for review March 19, 2024 10:45
@SamarthShukla17
Copy link
Author

@possumbilities, @TimidRobot and @annatuma I have updated the JavaScript of the scroll to just define a certain scroll to make the scroll back to top button appear, i.e., 1000 px and have created an anchor tag in html and linked it with the top of the page to completely remove any requirement of extra JavaScript. This makes the code more concise and apt. Kindly review it and provide feedback if any further changes are required. Thanks❤️❤️.

@possumbilities possumbilities requested review from possumbilities and removed request for TimidRobot and annatuma March 20, 2024 19:21
docs/index.html Outdated Show resolved Hide resolved
docs/index.html Outdated Show resolved Hide resolved
@possumbilities possumbilities mentioned this pull request Mar 22, 2024
7 tasks
@SamarthShukla17 SamarthShukla17 marked this pull request as draft March 26, 2024 11:12
Created a separate JS file for the scroll behavior.
@SamarthShukla17 SamarthShukla17 marked this pull request as ready for review March 26, 2024 11:16
@SamarthShukla17
Copy link
Author

Hey @possumbilities, I have created a separate file for JS, removing any requirement for the href"#" and also added a smooth behaviour on scroll.

@TimidRobot TimidRobot changed the title Created_Scroll_back_to_top Create a scroll back to top button Apr 8, 2024
docs/scroll.js Outdated Show resolved Hide resolved
docs/style.css Outdated Show resolved Hide resolved
docs/style.css Outdated Show resolved Hide resolved
Added the required end of the files and also fixed the document indentation of css file.
@TimidRobot
Copy link
Member

@SamarthShukla17 please resolve conflicts

@SamarthShukla17
Copy link
Author

Resolved the conflicts.

docs/scroll.js Outdated
@@ -0,0 +1,11 @@
document.addEventListener("DOMContentLoaded", function() {
let stt = document.getElementById("stt");
Copy link
Contributor

@possumbilities possumbilities Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the element in question is changed to only have a class, you'd need to use a querySelector to grab it by class here, but if not then disregard.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

docs/index.html Outdated

<h2 style="text-align: center; "><a href="/all">See all</a></h2>

<a href="#the-top" class="stt" id="stt" title="scroll to top">Back To Top</a>
Copy link
Contributor

@possumbilities possumbilities Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd opt for a class here, rather than an id. We don't need both. If there's good cause for the id instead, I'm open to it, but its redundant to have both.

I'd also suggest it be spelled out to be more semantic and descriptive.

So rather than a class or id of: stt, it would be better as scroll-to-top

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@possumbilities
Copy link
Contributor

@SamarthShukla17 I added two minor comments. That should be the remainder of adjustments. I'll give this a small window to make those adjustments before moving to Approval.

Removed id tag, as only class will do the work, changed the class name and replaced getElementById with querySelector.
@SamarthShukla17
Copy link
Author

Resolved the remainder of adjustments as required.❤️❤️

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SamarthShukla17 I think you've accidentally added a bunch of html here you didn't mean to?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I'm sorry about that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reverted the changes in the commit, kindly review.

@possumbilities
Copy link
Contributor

@SamarthShukla17 It looks like you've reverted a number of changes in the repository and now there's 133 files showing as affected in some way.

@possumbilities
Copy link
Contributor

@SamarthShukla17 Hi! are you intending to come back and clean up these last few commits? (if not, I'm going to close this PR)

@possumbilities
Copy link
Contributor

@SamarthShukla17 pinging you here again, before I close this.

@SamarthShukla17
Copy link
Author

Hey, I am really sorry for not being able to respond and resolve the issue, I'll try my best to complete the required task.

@possumbilities
Copy link
Contributor

Closing this and moving the area of focus to Vocabulary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⛔️ status: discarded Will not be worked on
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Feature] Add a scroll back to top button
4 participants