Toggle Element With Smooth CSS3 Transitions

slide-element

A Promise-based, jQuery-reminiscent collection of functions to help hide and show elements in a sliding fashion.

Under the Hood

This library relies on CSS animations to perform the transitions, but doesn’t require elements to have fixed heights. Instead, element heights are calculated based on their contents and padding (if applicable), and then the appropriate values are then applied to trigger a native transition. In all, slide-element comes in at under 1kb gzipped.

Installation

npm install slide-element

Setup

Make sure your target element is set to display: none, whether that’s with a class or inline style.

Usage

Toggling Elements

Use the toggle function to slide an element open & closed based on its current state.

import { toggle } from "slide-element";

document.getElementById("button").addEventListener("click", (e) => {
  toggle(document.getElementById("box"));
});

Sliding Elements Down

Use the down function to slide an element open.

import { down } from "slide-element";

down(document.getElementById("boxToSlideOpen"));

Sliding Elements Up

Use the up function to slide an element closed, and then set its display property to none.

import { up } from "slide-element";

up(document.getElementById("boxToSlideClosed"));

Everything’s a Promise

Each of the functions provided return promises, so you can easily wait to perform an action after an animation is complete. The resolved value will be a boolean indicating if the element has just been opened (true) or closed (false).

import { toggle } from "slide-element";

toggle(document.getElementById("someElement")).then((opened) => {
  console.log("toggling is done!");
});

Customizing the Animation

Each function accepts an object to control how the sliding animation executes. You can set your own duration and timingFunction values.

import { up } from "slide-element";

const anElement = document.getElementById("anElement");

up(anElement, { duration: 0.5, timingFunction: "linear" });

Options

Option Type Description Default
duration number The speed of the transition in seconds. .25
timingFunction string The CSS timing function used to define the style of transition. ease

Usage w/o a Bundler

If you’d like to use slide-element directly in the browser via CDN, simply load the code, and then reference the function you’d like to use on the global SlideElement object:

<script src="./dist/slide-element.min.js"></script>
<script>
  document.getElementById('someElement').addEventListener('click', (e) => {
    SlideElement.toggle(document.getElementById('someBox'));
});
</script>

API

toggle(node[, options]), up(node[, options]), down(node[, options]),

Param Type Description
node Node A single HTML node to be slid open or closed
options object Options to customize sliding animation.

Contributions

Go for it. Just send a PR.

Download Details:

Author: alexmacarthur

Demo: https://alexmacarthur.github.io/slide-element/

Source Code: https://github.com/alexmacarthur/slide-element

#css #css3 #javascript

What is GEEK

Buddha Community

Toggle Element With Smooth CSS3 Transitions

Ayan Code

1657830250

Dark Mode Toggle Button in JavaScript | Source code

Hey Devs, Today in this post we’ll learn How to Create a Dark Mode Toggle Button in JavaScript with fantastic design. Hope you enjoy this post.

Adding a dark/light mode feature on a website has been on rising. You could have already seen them on different websites. This feature enhances quality and user satisfaction. Various websites like YouTube, and Facebook have introduced such dark mode features.

Let's head to create it!

Demo

Click to watch demo!

Dark Mode Toggle Button in JavaScript | source code

HTML Code

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="style.css" />
  </head>

  <div class="all">
    <div class="container">
        <input type="checkbox" id="toggle">
    </div>

    <p>
        Lorem30
    </p>
   </div>

    <script src="script.js"></script>
  </body>
</html>

CSS Code

*{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    padding: 30px;
}
.all{
  width: 400px;
  margin: 40px auto;
}
.container{
    width: 100%;
    height: 40px;
    margin-bottom: 20px;
    position: relative;
}
#toggle{
    -webkit-appearance: none;
    appearance: none;
    height: 32px;
    width: 65px;
    background-color: #15181f;
    position: absolute;
    right: 0;
    border-radius: 20px;
    outline: none;
    cursor: pointer;
}
#toggle:after{
    content: "";
    position: absolute;
    height: 24px;
    width: 24px;
    background-color: #ffffff;
    top: 5px;
    left: 7px;
    border-radius: 50%;
}
p{
    font-family: "Open Sans",sans-serif;
    line-height: 35px;
    padding: 10px;
    text-align: justify;
    }
.dark-theme{
    background-color: #15181f;
    color: #e5e5e5;
}
.dark-theme #toggle{
    background-color: #ffffff;
}
.dark-theme #toggle:after{
    background-color: transparent;
    box-shadow: 10px 10px #15181f;
    top: -4px;
    left: 30px;
}

JavaScript Code

document.getElementById("toggle").addEventListener("click", function()
{
    document.getElementsByTagName('body')[0].classList.toggle("dark-theme");
});

Congratulations! You have now successfully created our Dark Mode Toggle Button in JavaScript.

My Website: codewithayan, see this to check out all of my amazing Tutorials.

Toggle Element With Smooth CSS3 Transitions

slide-element

A Promise-based, jQuery-reminiscent collection of functions to help hide and show elements in a sliding fashion.

Under the Hood

This library relies on CSS animations to perform the transitions, but doesn’t require elements to have fixed heights. Instead, element heights are calculated based on their contents and padding (if applicable), and then the appropriate values are then applied to trigger a native transition. In all, slide-element comes in at under 1kb gzipped.

Installation

npm install slide-element

Setup

Make sure your target element is set to display: none, whether that’s with a class or inline style.

Usage

Toggling Elements

Use the toggle function to slide an element open & closed based on its current state.

import { toggle } from "slide-element";

document.getElementById("button").addEventListener("click", (e) => {
  toggle(document.getElementById("box"));
});

Sliding Elements Down

Use the down function to slide an element open.

import { down } from "slide-element";

down(document.getElementById("boxToSlideOpen"));

Sliding Elements Up

Use the up function to slide an element closed, and then set its display property to none.

import { up } from "slide-element";

up(document.getElementById("boxToSlideClosed"));

Everything’s a Promise

Each of the functions provided return promises, so you can easily wait to perform an action after an animation is complete. The resolved value will be a boolean indicating if the element has just been opened (true) or closed (false).

import { toggle } from "slide-element";

toggle(document.getElementById("someElement")).then((opened) => {
  console.log("toggling is done!");
});

Customizing the Animation

Each function accepts an object to control how the sliding animation executes. You can set your own duration and timingFunction values.

import { up } from "slide-element";

const anElement = document.getElementById("anElement");

up(anElement, { duration: 0.5, timingFunction: "linear" });

Options

Option Type Description Default
duration number The speed of the transition in seconds. .25
timingFunction string The CSS timing function used to define the style of transition. ease

Usage w/o a Bundler

If you’d like to use slide-element directly in the browser via CDN, simply load the code, and then reference the function you’d like to use on the global SlideElement object:

<script src="./dist/slide-element.min.js"></script>
<script>
  document.getElementById('someElement').addEventListener('click', (e) => {
    SlideElement.toggle(document.getElementById('someBox'));
});
</script>

API

toggle(node[, options]), up(node[, options]), down(node[, options]),

Param Type Description
node Node A single HTML node to be slid open or closed
options object Options to customize sliding animation.

Contributions

Go for it. Just send a PR.

Download Details:

Author: alexmacarthur

Demo: https://alexmacarthur.github.io/slide-element/

Source Code: https://github.com/alexmacarthur/slide-element

#css #css3 #javascript

Samuel Tucker

Samuel Tucker

1663207274

Light/Dark Mode Switch with HTML, CSS & Vanilla JavaScript

Learn how to create a dark mode switch with HTML, CSS & Vanilla Javascript. When the user clicks on this switch, the theme of the webpage/website toggles between dark and light mode. With this tutorial, you will get a basic idea of how you can add a dark theme option to your website without changing much code or without adding excessive CSS.

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Dark Mode Toggle</title>
    <!--Google Fonts-->
    <link href="https://fonts.googleapis.com/css2?family=Work+Sans&display=swap" rel="stylesheet">
    <!--Stylesheet-->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <input type="checkbox" id="toggle">
    </div>
    <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis, ab sequi! Ipsum, reprehenderit! Dolor vero sunt corporis ea natus, nulla cum assumenda. Nostrum corporis molestiae corrupti magni. Corporis ducimus ipsam, qui et eveniet nisi excepturi sint dolore, labore velit repellat quia quasi! Repellendus quo magni voluptatem aut odit, totam sequi autem, doloremque minima tenetur placeat debitis reiciendis repudiandae dolore tempore adipisci blanditiis reprehenderit doloribus recusandae esse commodi harum ratione quisquam?
    </p>
    <script src="script.js"></script>
</body>
</html>

CSS:

*,
*:before,
*:after{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    padding: 30px;
}
.container{
    width: 100%;
    height: 40px;
    position: relative;
    margin-bottom: 30px;
}
#toggle{
    -webkit-appearance: none;
    appearance: none;
    height: 40px;
    width: 75px;
    background-color: #15181f;
    position: absolute;
    right: 0;
    border-radius: 20px;
    outline: none;
    cursor: pointer;
}
#toggle:after{
    content: "";
    position: absolute;
    height: 30px;
    width: 30px;
    background-color: #ffffff;
    top: 5px;
    left: 7px;
    border-radius: 50%;
}
p{
    font-family: "Open Sans",sans-serif;
    line-height: 35px;
    text-align: justify;
}
.dark-theme{
    background-color: #15181f;
    color: #e5e5e5;
}
.dark-theme #toggle{
    background-color: #ffffff;
}
.dark-theme #toggle:after{
    background-color: transparent;
    box-shadow: 10px 10px #15181f;
    top: -4px;
    left: 30px;
}

Javascript:

document.getElementById("toggle").addEventListener("click", function(){
    document.getElementsByTagName('body')[0].classList.toggle("dark-theme");
});

Related Videos

CSS & Javascript Toggle Button | Dark and Light Mode

Light/Dark Theme Toggle with CSS and JavaScript

Toggle Between Dark and Light Mode using HTML, CSS & JavaScript

How to make a website light/dark toggle with CSS & JS

How To Make Website DARK MODE | Dark Theme Website Design Using HTML, CSS & JS

#html #css #javascript

野村  陽一

野村 陽一

1638056820

Javascriptでのダーク&ライトモードの切り替え

ダークテーマは、ウェブサイトのデザインの最も重要な側面の1つです。これは、過去数年間のトレンド機能です。これの主な理由の1つは、特にそれほど照らされていないスペースで、高輝度による目の負担を避け、安全性を提供することです。

今日のチュートリアルでは、ダークモードスイッチを作成する方法を学習します。ユーザーがこのスイッチをクリックすると、Webページ/ Webサイトのテーマがダークモードとライトモードの間で切り替わります。このチュートリアルでは、コードを大幅に変更したり、CSSを過剰に追加したりせずに、ダークテーマオプションをWebサイトに追加する方法の基本的な考え方を理解できます。

UIデザインのダークテーマに関しては、すべきこととすべきでないことがいくつかあります。このチュートリアルでは、それらについて簡単に説明します。このチュートリアルでは、HTML、CSS、VanillaJavascriptが必要です。私たちが使用するJavaScriptコードはそれほど複雑ではないので、心配する必要はありません。それでは、チュートリアルを始めましょう。

HTML:

HTMLファイルを作成し、「index.html」という名前で保存します。以下に提供するコードをコピーして、HTMLファイルに貼り付けてください。
HTMLには多くの要素が含まれていません。クラス名「container」で「div」要素を作成しましょう。コンテナはチェックボックスを閉じます。このチェックボックスには、「toggle」という名前のIDを割り当てます。ここでチェックボックスを使用する理由は、スタイルを設定してトグルスイッチとして使用するためです。
次に、HTMLにデモテキストを追加する必要があります。この目的のために、いくつかの「loremipsum」テキストを追加しています。

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Dark Mode Toggle</title>
    <!--Google Fonts-->
    <link href="https://fonts.googleapis.com/css2?family=Work+Sans&display=swap" rel="stylesheet">
    <!--Stylesheet-->
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <input type="checkbox" id="toggle">
    </div>
    <p>
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Facilis, ab sequi! Ipsum, reprehenderit! Dolor vero sunt corporis ea natus, nulla cum assumenda. Nostrum corporis molestiae corrupti magni. Corporis ducimus ipsam, qui et eveniet nisi excepturi sint dolore, labore velit repellat quia quasi! Repellendus quo magni voluptatem aut odit, totam sequi autem, doloremque minima tenetur placeat debitis reiciendis repudiandae dolore tempore adipisci blanditiis reprehenderit doloribus recusandae esse commodi harum ratione quisquam?
    </p>
    <script src="script.js"></script>
</body>
</html>

CSS:

スタイルシートを作成し、「style.css」という名前を付けます。次に、以下のコードをコピーして、スタイルシートに貼り付けます。

まず、ボディにパディングを追加します。次に、幅を追加し、コンテナを中央に配置します。チェックボックスをトグルスイッチのようにスタイル設定するには、疑似要素の「後」に配置します。「後」の疑似要素は、太陽を表す円のように見えます。

暗いテーマのクラスにスタイルを追加する必要があります。このクラスは、ユーザーがトグルをクリックしたときに本体に適用されます。

ダークテーマでは、背景色は「#15181f」に設定されます。灰色またはより暗い灰色の色合いを使用します。黒の使用は避けてください。全体的に黒い色は眼精疲労を引き起こす可能性があります。グレーの濃い色合いがより適しています。フォントの色については、彩度の低いバージョンの白を選択します。
 

暗闇の中で、テーマのスイッチの背景色が白に変わります(または彩度の低いバージョンの白を使用できます)。'after'疑似要素は、box-shadowプロパティを使用して月のように見えるように作成されます。

*,
*:before,
*:after{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}
body{
    padding: 30px;
}
.container{
    width: 100%;
    height: 40px;
    position: relative;
    margin-bottom: 30px;
}
#toggle{
    -webkit-appearance: none;
    appearance: none;
    height: 40px;
    width: 75px;
    background-color: #15181f;
    position: absolute;
    right: 0;
    border-radius: 20px;
    outline: none;
    cursor: pointer;
}
#toggle:after{
    content: "";
    position: absolute;
    height: 30px;
    width: 30px;
    background-color: #ffffff;
    top: 5px;
    left: 7px;
    border-radius: 50%;
}
p{
    font-family: "Open Sans",sans-serif;
    line-height: 35px;
    text-align: justify;
}
.dark-theme{
    background-color: #15181f;
    color: #e5e5e5;
}
.dark-theme #toggle{
    background-color: #ffffff;
}
.dark-theme #toggle:after{
    background-color: transparent;
    box-shadow: 10px 10px #15181f;
    top: -4px;
    left: 30px;
}

Javascript:

最後のステップとして、このトグルを機能させるための機能を追加する必要があります。'script.js'というJavaScriptファイルを作成します。ここに記載されているコードをコピーして、スクリプトファイルに貼り付けます。

javascriptで行う唯一のことは、「クリック」イベントリスナーをトグルに追加することです。クリックイベントでは、ドキュメント本文で「ダークテーマ」クラスが切り替えられます。このようにして、ユーザーがスイッチをクリックすると、ダークモードが追加および削除されます。

document.getElementById("toggle").addEventListener("click", function(){
    document.getElementsByTagName('body')[0].classList.toggle("dark-theme");
});

これでダークモードスイッチの準備が整いました。これは、Webページにダークモードを追加する方法の1つを紹介する小さな例ですが、先に進んでこれを展開し、Webサイト全体にダークモードを追加できます。このチュートリアルが気に入ったら、必ず私のYouTubeチャンネルをチェックしください次のチュートリアルでお会いしましょう。


リンク: https://codingartistweb.com/2021/07/dark-light-mode-toggle-javascript/

#javascript 

 

 iOS App Dev

iOS App Dev

1655889360

Element IOS: A Glossy Matrix Collaboration Client for IOS

Element iOS

Element iOS is an iOS Matrix client provided by Element. It is based on MatrixSDK. 

Beta testing

You can try last beta build by accessing our TestFlight Public Link. For questions and feedback about latest TestFlight build, please access the Element iOS Matrix room: #element-ios:matrix.org.

Build instructions

If you have already everything installed, opening the project workspace in Xcode should be as easy as:

$ xcodegen                  # Create the xcodeproj with all project source files
$ pod install               # Create the xcworkspace with all project dependencies
$ open Riot.xcworkspace     # Open Xcode

Else, you can visit our installation guide. This guide also offers more details and advanced usage like using MatrixSDK in its development version.

Contributing

If you want to contribute to Element iOS code or translations, go to the contribution guide.

Support

When you are experiencing an issue on Element iOS, please first search in GitHub issues and then in #element-ios:matrix.org. If after your research you still have a question, ask at #element-ios:matrix.org. Otherwise feel free to create a GitHub issue if you encounter a bug or a crash, by explaining clearly in detail what happened. You can also perform bug reporting (Rageshake) from the Element application by shaking your phone or going to the application settings. This is especially recommended when you encounter a crash.

Download Details:
Author: vector-im
Source Code: https://github.com/vector-im/element-ios
License: Apache-2.0 license

#swift #ios #mobileapp