Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Add a new snippet: CSS toggle switch #98

Merged
merged 12 commits into from
Oct 3, 2018
Merged

Add a new snippet: CSS toggle switch #98

merged 12 commits into from
Oct 3, 2018

Conversation

daihuaye
Copy link
Contributor

No description provided.

@atomiks
Copy link
Contributor

atomiks commented Sep 30, 2018

Another great snippet. Couple suggestions:

  • Transition for the knob?
  • More aesthetically pleasing color than blue?

Looks great other than that

@daihuaye
Copy link
Contributor Author

daihuaye commented Oct 1, 2018

@atomiks Thanks for your comment. It's a good point. I have added transition for label's background color and the knob. And I pick the color #7983ff, if you have any suggestion, please let me know.

@atomiks
Copy link
Contributor

atomiks commented Oct 1, 2018

One thing I noticed, and it's extremely subtle, but the knob has tiny 1px jerks as it finishes the transition because it's translating left instead of transform. transform uses subpixels instead of whole pixels which looks better (especially on HiDPI displays) and is more performant to animate.

I think you can do this:

input[type="checkbox"]:checked+.switch::after {
  left: 0;
  transform: translateX(21px);
  /* remove margin-left: -1px */
}

Edit: it also may not be accessible?

.offscreen {
  /* remove display: none; */
  position: absolute;
  left: -9999px;
}

@daihuaye
Copy link
Contributor Author

daihuaye commented Oct 1, 2018

@atomiks Thanks! That's good suggestion. I agree that use transform will help animation and is more smooth than use left property. Also yeah, the your change for .offscreen will help accessibility.

One thing is the translateX(21px) will make the knob touch the edge of <label> container, It will look good if there is 1px off, which is the same as start state, right?

@atomiks
Copy link
Contributor

atomiks commented Oct 2, 2018

One thing is the translateX(21px) will make the knob touch the edge of container, It will look good if there is 1px off, which is the same as start state, right?

With left: 0, you need 21px, but if we don't set left at all, we only need 20px because of the original left: 1px.

I've made some improvements and I think it's ready now 👍

@daihuaye
Copy link
Contributor Author

daihuaye commented Oct 2, 2018

Looks good to me. Thanks!

Copy link
Contributor

@skatcat31 skatcat31 left a comment

Choose a reason for hiding this comment

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

The recent changes make it smoother. nice

@daihuaye
Copy link
Contributor Author

daihuaye commented Oct 3, 2018

@atomiks Any more comment? Just wonder when will it merge to master branch if everything looks good?

@atomiks atomiks merged commit 2afb2fe into Chalarangelo:master Oct 3, 2018
@lock
Copy link

lock bot commented Dec 18, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants