Advertisement

How to Completely Remove OneDrive from Windows 10 Creator’s Build Version 1073

NOTE:  This fix does not work on Windows 10 Home.  

OneDrive (previously SkyDrive, Windows Live SkyDrive and Windows Live Folders) is a personal cloud file hosting, storage and sync service from Microsoft. In Windows 10, the OneDrive desktop app is installed and comes natively with the operating system. And if you sign into Windows 10 with a Microsoft Account (MSA), OneDrive is also enabled by default.

However, not everyone uses OneDrive. Some may prefer other similar cloud storage services such as Dropbox, Google Drive, Apple iCloud Drive, Box and many more. Or many may simply not using any cloud storage service or file hosting service at all, especially at computers used in businesses, corporations, enterprises, schools and educational institutions.

Unlike Windows 8.1, Windows 8, Windows 7 or earlier Windows operating systems, OneDrive desktop app is tightly integrated with Windows 10. OneDrive folder is in File Explorer’s navigation pane right from the moment you starting to use Windows 10. In fact, by default Windows 10 does not provide a way for users to uninstall and remove OneDrive app, whether it’s from “Programs and Features” of “Control Panel” or Windows Store. You simply won’t find any OneDrive entry to initiate the uninstallation process.

However, there are several ways available in Windows 10 to deal with OneDrive app, depending on whether you want to hide, disable, remove or uninstall the OneDrive. The tutorial provides all the options available with step-by-step guide.

Official Way to Uninstall OneDrive via Settings or Control Panel

Beginning from Windows 10 Creators Update Version 1703 (or more specifically beginning from Windows 10 Build 14986), OneDrive is showing as a standalone app in Apps & features section of Settings and Programs & Features section of Control Panel, and hence, could be uninstalled via official uninstaller.

Here’s how to uninstall OneDrive via Settings or Control Panel. Do note that Windows 10 may still have some remnants of OneDrive such as shortcuts after removal.

Disable OneDrive Everywhere in Windows and Apps Completely

  1. Press Win + R keyboard accelerator to open Run dialog box.
  2. Type GPedit.msc and hit Enter or OK to open Local Group Policy Editor.
  3. Navigate to Local Computer Policy -> Computer Configuration -> Administrative Templates -> WindowsComponents -> OneDrive.
  4. In the right pane, double click on policy named Prevent the usage of OneDrive for file storage.
  5. Select the Enabled radio button.Disable OneDrive
  6. Click or tap OK when done.

That’s it. OneDrive icon is hidden from Explorer, and OneDrive app is completely disabled and prevented from running, and access or work with files on OneDrive from any desktop apps or modern apps is blocked. For example:

  • Can’t access OneDrive from the OneDrive app and file picker.
  • Windows Store apps can’t access OneDrive using the WinRT API.
  • OneDrive doesn’t appear in the navigation pane in File Explorer.
  • OneDrive files aren’t kept in sync with the cloud.
  • Can’t automatically upload photos and videos from the camera roll folder.
  • Sign out and sign in again, or restart the computer.
Registry Settings

The policy above is actually set a setting in Registry, which is useful for people who prefer to use Registry Editor. In addition, Windows 10 Home does not come with Group Policy Editor too.Here’s how to use Registry Editor to turn off OneDrive everywhere completely:

  1. Press Win + R keyboard accelerator to open Run dialog box.
  2. Type RegEdit.exe and hit Enter or OK to open Registry Editor.
  3. Navigate to the following registry key:HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows
  4. Right click on Windows and select New -> Key. Name the new key as OneDrive.Note: If OneDrive key already exists, skip this step.
  5. Right click on OneDrive registry key, and select New -> DWORD (32-bit) Value. Name the new value name as DisableFileSyncNGSC
  6. Set the data for DisableFileSyncNGSC registry value as 1.Turn Off OneDrive in Registry
  7. Note: DisableFileSync registry value only works in Windows 7, Windows 8 and Windows 8.1 and does not work in Windows 10.
  8. Close Registry Editor.
  9. Sign out and sign in again, or restart the computer.

Hide and Remove OneDrive from Navigation Pane of Windows Explorer

If you just want to remove the OneDrive entry in the navigation pane (also known as side panel or folder tree) in the File Explorer, or the OneDrive folder still exists in File Explorer after disabling OneDrive, follow the guide to remove OneDrive from Windows 10 File Explorer Navigation Side Panel.

Complete Remove and Uninstall OneDrive

It’s impossible to manually uninstall and remove OneDrive in Windows 10 by the step-by-step guide below. Run the commands to be executed in the process below in an Administrator Command Prompt.

Uninstall OneDrive

  1. Terminate any process of OneDrive by running the following command:
    taskkill /f /im OneDrive.exe
  2. Uninstall OneDrive app by running one of the following command:In 32-bit Windows 10 (x86):
    %SystemRoot%\System32\OneDriveSetup.exe /uninstall

    In 64-bit Windows 10 (x64):

    %SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall

One you ran the above command, OneDrive desktop app is uninstalled completely and cleanly. Most of the time, no progress bar nor confirmation dialog is shown. However, when you search for OneDrive, the app no longer be found.

Cleaning and Removing OneDrive Remnants

However, as OneDrive is a cloud storage service which is dealing with user data, there are remnants and leftovers from OneDrive app that are still available on the system as uninstallation does not remove user data, most prominently been the OneDrive folder. Run the commands below to clean up those remnants by deleting OneDrive related folders and their contents:

Important
Make sure that the following folders no longer contain any user data before proceeding with the following commands.
rd "%UserProfile%\OneDrive" /Q /S
rd "%LocalAppData%\Microsoft\OneDrive" /Q /S
rd "%ProgramData%\Microsoft OneDrive" /Q /S
rd "C:\OneDriveTemp" /Q /S

Delete and Remove OneDrive in File Explorer Folder Tree Registry Key

OneDrive has registry keys which add itself to the Navigation Pane of File Explorer in Windows 10. After uninstalling OneDrive, these registry keys are orphaned, and can be removed.

REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f

How to Completely Remove OneDrive from Windows 10 Creator's Build Version 1073

NOTE:  This fix does not work on Windows 10 Home.  
OneDrive (previously SkyDrive, Windows Live SkyDrive and Windows Live Folders) is a personal cloud file hosting, storage and sync service from Microsoft. In Windows 10, the OneDrive desktop app is installed and comes natively with the operating system. And if you sign into Windows 10 with a Microsoft Account (MSA), OneDrive is also enabled by default.
However, not everyone uses OneDrive. Some may prefer other similar cloud storage services such as Dropbox, Google Drive, Apple iCloud Drive, Box and many more. Or many may simply not using any cloud storage service or file hosting service at all, especially at computers used in businesses, corporations, enterprises, schools and educational institutions.
Unlike Windows 8.1, Windows 8, Windows 7 or earlier Windows operating systems, OneDrive desktop app is tightly integrated with Windows 10. OneDrive folder is in File Explorer’s navigation pane right from the moment you starting to use Windows 10. In fact, by default Windows 10 does not provide a way for users to uninstall and remove OneDrive app, whether it’s from “Programs and Features” of “Control Panel” or Windows Store. You simply won’t find any OneDrive entry to initiate the uninstallation process.
However, there are several ways available in Windows 10 to deal with OneDrive app, depending on whether you want to hide, disable, remove or uninstall the OneDrive. The tutorial provides all the options available with step-by-step guide.
Official Way to Uninstall OneDrive via Settings or Control Panel
Beginning from Windows 10 Creators Update Version 1703 (or more specifically beginning from Windows 10 Build 14986), OneDrive is showing as a standalone app in Apps & features section of Settings and Programs & Features section of Control Panel, and hence, could be uninstalled via official uninstaller.
Here’s how to uninstall OneDrive via Settings or Control Panel. Do note that Windows 10 may still have some remnants of OneDrive such as shortcuts after removal.
Disable OneDrive Everywhere in Windows and Apps Completely

  1. Press Win + R keyboard accelerator to open Run dialog box.
  2. Type GPedit.msc and hit Enter or OK to open Local Group Policy Editor.
  3. Navigate to Local Computer Policy -> Computer Configuration -> Administrative Templates -> WindowsComponents -> OneDrive.
  4. In the right pane, double click on policy named Prevent the usage of OneDrive for file storage.
  5. Select the Enabled radio button.Disable OneDrive
  6. Click or tap OK when done.

That’s it. OneDrive icon is hidden from Explorer, and OneDrive app is completely disabled and prevented from running, and access or work with files on OneDrive from any desktop apps or modern apps is blocked. For example:

  • Can’t access OneDrive from the OneDrive app and file picker.
  • Windows Store apps can’t access OneDrive using the WinRT API.
  • OneDrive doesn’t appear in the navigation pane in File Explorer.
  • OneDrive files aren’t kept in sync with the cloud.
  • Can’t automatically upload photos and videos from the camera roll folder.
  • Sign out and sign in again, or restart the computer.
Registry Settings
The policy above is actually set a setting in Registry, which is useful for people who prefer to use Registry Editor. In addition, Windows 10 Home does not come with Group Policy Editor too.Here’s how to use Registry Editor to turn off OneDrive everywhere completely:

  1. Press Win + R keyboard accelerator to open Run dialog box.
  2. Type RegEdit.exe and hit Enter or OK to open Registry Editor.
  3. Navigate to the following registry key:HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows
  4. Right click on Windows and select New -> Key. Name the new key as OneDrive.Note: If OneDrive key already exists, skip this step.
  5. Right click on OneDrive registry key, and select New -> DWORD (32-bit) Value. Name the new value name as DisableFileSyncNGSC
  6. Set the data for DisableFileSyncNGSC registry value as 1.Turn Off OneDrive in Registry
  7. Note: DisableFileSync registry value only works in Windows 7, Windows 8 and Windows 8.1 and does not work in Windows 10.
  8. Close Registry Editor.
  9. Sign out and sign in again, or restart the computer.

Hide and Remove OneDrive from Navigation Pane of Windows Explorer
If you just want to remove the OneDrive entry in the navigation pane (also known as side panel or folder tree) in the File Explorer, or the OneDrive folder still exists in File Explorer after disabling OneDrive, follow the guide to remove OneDrive from Windows 10 File Explorer Navigation Side Panel.
Complete Remove and Uninstall OneDrive
It’s impossible to manually uninstall and remove OneDrive in Windows 10 by the step-by-step guide below. Run the commands to be executed in the process below in an Administrator Command Prompt.
Uninstall OneDrive

  1. Terminate any process of OneDrive by running the following command:
    taskkill /f /im OneDrive.exe
  2. Uninstall OneDrive app by running one of the following command:In 32-bit Windows 10 (x86):
    %SystemRoot%\System32\OneDriveSetup.exe /uninstall

    In 64-bit Windows 10 (x64):

    %SystemRoot%\SysWOW64\OneDriveSetup.exe /uninstall

One you ran the above command, OneDrive desktop app is uninstalled completely and cleanly. Most of the time, no progress bar nor confirmation dialog is shown. However, when you search for OneDrive, the app no longer be found.
Cleaning and Removing OneDrive Remnants
However, as OneDrive is a cloud storage service which is dealing with user data, there are remnants and leftovers from OneDrive app that are still available on the system as uninstallation does not remove user data, most prominently been the OneDrive folder. Run the commands below to clean up those remnants by deleting OneDrive related folders and their contents:

Important
Make sure that the following folders no longer contain any user data before proceeding with the following commands.
rd "%UserProfile%\OneDrive" /Q /S
rd "%LocalAppData%\Microsoft\OneDrive" /Q /S
rd "%ProgramData%\Microsoft OneDrive" /Q /S
rd "C:\OneDriveTemp" /Q /S

Delete and Remove OneDrive in File Explorer Folder Tree Registry Key
OneDrive has registry keys which add itself to the Navigation Pane of File Explorer in Windows 10. After uninstalling OneDrive, these registry keys are orphaned, and can be removed.

REG Delete "HKEY_CLASSES_ROOT\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f
REG Delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}" /f

Continue reading “How to Completely Remove OneDrive from Windows 10 Creator's Build Version 1073”

Easily Customize the WordPress Menu with Custom Classes

WordPress is really powerful, but we all know that out of the box it is pretty stiff, right?  So what if you want to spice up your menu a bit but you don’t want to get into the guts of the code to do so?  This tutorial is for you.

So the standard WordPress Menu looks something like this:

Pretty standard stuff.  Not very exciting.  Works but we can make it better.  Since WordPress 2.0 we have an addition to the display settings in the editor pages for when we use the menu creation engine at WordPress.  This allows us to assign custom classes to each menu item.  When you navigate to the Menu Admin area and click the Screen Options button at the top right of the page, here’s how to activate this feature:

Do you see the CSS CLASSES check box?  Check it.  When you return to your menu item you will see a new box that has been added there:

You can enter any descriptor into the box.  Just make sure that you DO NOT use ANY special characters and ESPECIALLY not # (pound sign) or . (period).  Once you enter this descriptor (something like blue-background) just click to save the menu.

Next you can go to the either the customizer or use your child theme .CSS file to add your custom CSS.  For this demonstration we will use the following code:

.blue-background a:hover{background:blue; border-radius:5px; color:white;}

This allows us on hovering over the menu item to have a blue background with slightly rounded corners and with the button text white.

Pretty easy right!

If you liked our tutorials then please show your love by following or connecting with us on one of our Social Media Channels! Continue reading “Easily Customize the WordPress Menu with Custom Classes”

How to Create Animations using Javascript

Learn how to create animations using JavaScript.


A Basic Web Page

To demonstrate how to create HTML animations with JavaScript, we can use a simple web page.

CODE:

<!DOCTYPE html>
<html>
<body><h1>My First JavaScript Animation</h1><div id =”myContainer”>
<div id =”myAnimation”>My animation will go here</div>
</div>

</body>
<html>


Styling the Elements

To make an animation possible, the animated element must be animated relative to a “parent container”.

The container element should be created with style = “position: relative”.

The animation element should be created with style = “position: absolute”.

CODE:

#myContainer {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#myAnimation {
width: 50px;
height: 50px;
position: absolute;
background: red;
}

The Animation Code

JavaScript animations are done by programming gradual changes in an element’s style.

The changes are called by a timer. When the timer interval is small, the animation looks continuous.

The basic code is:

CODE:

var id = setInterval(frame, 5);

function frame() {
if (/* test for finished */) {
clearInterval(id);
} else {
/* code to change the element style */
}
}


Create the Animation Using JavaScript

CODE:

function myMove() {
var elem = document.getElementById(“myAnimation”);
var pos = 0;
var id = setInterval(frame, 10);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + ‘px’;
elem.style.left = pos + ‘px’;
}
}
}

FULL CODE:

<!DOCTYPE html>
<html>
<style>
#myContainer {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#myAnimation {
width: 50px;
height: 50px;
position: absolute;
background-color: red;
}
</style>
<body>

<p>
<button onclick=”myMove()”>Click Me</button>
</p>

<div id =”myContainer”>
<div id =”myAnimation”></div>
</div>

<script>
function myMove() {
var elem = document.getElementById(“myAnimation”);
var pos = 0;
var id = setInterval(frame, 10);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + ‘px’;
elem.style.left = pos + ‘px’;
}
}
}
</script>

</body>
</html>


Continue reading “How to Create Animations using Javascript”

How to Create a Filter Table with Javascript

Learn how to create a filter table with JavaScript.


Filter Table

How to use JavaScript to search for specific data in a table.

Name Country
Alfreds Futterkiste Germany
Berglunds snabbkop Sweden
Island Trading UK
Koniglich Essen Germany
Laughing Bacchus Winecellars Canada
Magazzini Alimentari Riuniti Italy
North/South UK
Paris specialites France

Create A Filtered Table

Step 1) Add HTML:

Example

<input type=”text” id=”myInput” onkeyup=”myFunction()” placeholder=”Search for names..”>

<table id=”myTable”>
<tr class=”header”>
<th style=”width:60%;”>Name</th>
<th style=”width:40%;”>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Island Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Koniglich Essen</td>
<td>Germany</td>
</tr>
</table>


Step 2) Add CSS:

Style the input element and the table:

Example

#myInput {
background-image: url(‘/css/searchicon.png’); /* Add a search icon to input */
background-position: 10px 12px; /* Position the search icon */
background-repeat: no-repeat; /* Do not repeat the icon image */
width: 100%; /* Full-width */
font-size: 16px; /* Increase font-size */
padding: 12px 20px 12px 40px; /* Add some padding */
border: 1px solid #ddd; /* Add a grey border */
margin-bottom: 12px; /* Add some space below the input */
}#myTable {
border-collapse: collapse; /* Collapse borders */
width: 100%; /* Full-width */
border: 1px solid #ddd; /* Add a grey border */
font-size: 18px; /* Increase font-size */
}

#myTable th, #myTable td {
text-align: left; /* Left-align text */
padding: 12px; /* Add padding */
}

#myTable tr {
/* Add a bottom border to all table rows */
border-bottom: 1px solid #ddd;
}

#myTable tr.header, #myTable tr:hover {
/* Add a grey background color to the table header and on hover */
background-color: #f1f1f1;
}


Step 3) Add JavaScript:

Example

<script>
function myFunction() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById(“myInput”);
filter = input.value.toUpperCase();
table = document.getElementById(“myTable”);
tr = table.getElementsByTagName(“tr”);// Loop through all table rows, and hide those who don’t match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName(“td”)[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = “”;
} else {
tr[i].style.display = “none”;
}
}
}
}
</script>

Tip: Remove toUpperCase() if you want to perform a case-sensitive search.

Tip: Change tr[i].getElementsByTagName(‘td’)[0] to [1] if you want to search for “Country” (index 1) instead of “Name” (index 0).


FULL CODE:

CODE:

<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}

#myInput {
background-image: url(‘/css/searchicon.png’);
background-position: 10px 10px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}

#myTable {
border-collapse: collapse;
width: 100%;
border: 1px solid #ddd;
font-size: 18px;
}

#myTable th, #myTable td {
text-align: left;
padding: 12px;
}

#myTable tr {
border-bottom: 1px solid #ddd;
}

#myTable tr.header, #myTable tr:hover {
background-color: #f1f1f1;
}
</style>
</head>
<body>

<h2>My Customers</h2>

<input type=”text” id=”myInput” onkeyup=”myFunction()” placeholder=”Search for names..” title=”Type in a name”>

<table id=”myTable”>
<tr class=”header”>
<th style=”width:60%;”>Name</th>
<th style=”width:40%;”>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Germany</td>
</tr>
<tr>
<td>Berglunds snabbkop</td>
<td>Sweden</td>
</tr>
<tr>
<td>Island Trading</td>
<td>UK</td>
</tr>
<tr>
<td>Koniglich Essen</td>
<td>Germany</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Italy</td>
</tr>
<tr>
<td>North/South</td>
<td>UK</td>
</tr>
<tr>
<td>Paris specialites</td>
<td>France</td>
</tr>
</table>

<script>
function myFunction() {
var input, filter, table, tr, td, i;
input = document.getElementById(“myInput”);
filter = input.value.toUpperCase();
table = document.getElementById(“myTable”);
tr = table.getElementsByTagName(“tr”);
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName(“td”)[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = “”;
} else {
tr[i].style.display = “none”;
}
}
}
}
</script>

</body>
</html>


CLICK HERE TO VIEW WORKING FILTER TABLE

Continue reading “How to Create a Filter Table with Javascript”

How to Create a Filter List with Javascript

Learn how to create a filter list with JavaScript.


Filter List

How to use JavaScript to search for items in a list.


Create A Search List

Step 1) Add HTML:

CODE:

<input type=”text” id=”myInput” onkeyup=”myFunction()” placeholder=”Search for names..”>

<ul id=”myUL”>
<li><a href=”#” class=”header”>A</a></li>
<li><a href=”#”>Adele</a></li>
<li><a href=”#”>Agnes</a></li>

<li><a href=”#” class=”header”>B</a></li>
<li><a href=”#”>Billy</a></li>
<li><a href=”#”>Bob</a></li>

<li><a href=”#” class=”header”>C</a></li>
<li><a href=”#”>Calvin</a></li>
<li><a href=”#”>Christina</a></li>
<li><a href=”#”>Cindy</a></li>
</ul>

Note: We use href=”#” in this demo since we do not have a page to link it to. In real life this should be a real URL to a specific page.


Step 2) Add CSS:

Style the input element and the list:

CODE:

#myInput {
background-image: url(‘/css/searchicon.png’); /* Add a search icon to input */
background-position: 10px 12px; /* Position the search icon */
background-repeat: no-repeat; /* Do not repeat the icon image */
width: 100%; /* Full-width */
font-size: 16px; /* Increase font-size */
padding: 12px 20px 12px 40px; /* Add some padding */
border: 1px solid #ddd; /* Add a grey border */
margin-bottom: 12px; /* Add some space below the input */
}#myUL {
/* Remove default list styling */
list-style-type: none;
padding: 0;
margin: 0;
}

#myUL li a {
border: 1px solid #ddd; /* Add a border to all links */
margin-top: -1px; /* Prevent double borders */
background-color: #f6f6f6; /* Grey background color */
padding: 12px; /* Add some padding */
text-decoration: none; /* Remove default text underline */
font-size: 18px; /* Increase the font-size */
color: black; /* Add a black text color */
display: block; /* Make it into a block element to fill the whole list */
}

#myUL li a.header {
background-color: #e2e2e2; /* Add a darker background color for headers */
cursor: default; /* Change cursor style */
}

#myUL li a:hover:not(.header) {
background-color: #eee; /* Add a hover effect to all links, except for headers */
}


Step 3) Add JavaScript:

CODE:

<script>
function myFunction() {
// Declare variables
var input, filter, ul, li, a, i;
input = document.getElementById(‘myInput’);
filter = input.value.toUpperCase();
ul = document.getElementById(“myUL”);
li = ul.getElementsByTagName(‘li’);// Loop through all list items, and hide those who don’t match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName(“a”)[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = “”;
} else {
li[i].style.display = “none”;
}
}
}
</script>

Tip: Remove toUpperCase() if you want to perform a case-sensitive search.

FULL CODE:

CODE:

<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}

#myInput {
background-image: url(‘/css/searchicon.png’);
background-position: 10px 12px;
background-repeat: no-repeat;
width: 100%;
font-size: 16px;
padding: 12px 20px 12px 40px;
border: 1px solid #ddd;
margin-bottom: 12px;
}

#myUL {
list-style-type: none;
padding: 0;
margin: 0;
}

#myUL li a {
border: 1px solid #ddd;
margin-top: -1px; /* Prevent double borders */
background-color: #f6f6f6;
padding: 12px;
text-decoration: none;
font-size: 18px;
color: black;
display: block
}

#myUL li a.header {
background-color: #e2e2e2;
cursor: default;
}

#myUL li a:hover:not(.header) {
background-color: #eee;
}
</style>
</head>
<body>

<h2>My Phonebook</h2>

<input type=”text” id=”myInput” onkeyup=”myFunction()” placeholder=”Search for names..” title=”Type in a name”>

<ul id=”myUL”>
<li><a href=”#” class=”header”>A</a></li>
<li><a href=”#”>Adele</a></li>
<li><a href=”#”>Agnes</a></li>

<li><a href=”#” class=”header”>B</a></li>
<li><a href=”#”>Billy</a></li>
<li><a href=”#”>Bob</a></li>

<li><a href=”#” class=”header”>C</a></li>
<li><a href=”#”>Calvin</a></li>
<li><a href=”#”>Christina</a></li>
<li><a href=”#”>Cindy</a></li>
</ul>

<script>
function myFunction() {
var input, filter, ul, li, a, i;
input = document.getElementById(“myInput”);
filter = input.value.toUpperCase();
ul = document.getElementById(“myUL”);
li = ul.getElementsByTagName(“li”);
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName(“a”)[0];
if (a.innerHTML.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = “”;
} else {
li[i].style.display = “none”;

}
}
}
</script>

</body>
</html>


Continue reading “How to Create a Filter List with Javascript”

CSS & Javascript Modal Image Gallery

Learn how to create a modal image gallery (lightbox) with CSS and JavaScript.


Lightbox (Modal Image Gallery)

 


Create A Lightbox

Step 1) Add HTML:

CODE:

<div class=”row”>
<div class=”column”>
<img src=”img1.jpg” onclick=”openModal();currentSlide(1)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img2.jpg” onclick=”openModal();currentSlide(2)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img3.jpg” onclick=”openModal();currentSlide(3)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img4.jpg” onclick=”openModal();currentSlide(4)” class=”hover-shadow”>
</div>
</div><div id=”myModal” class=”modal”>
<span class=”close cursor” onclick=”closeModal()”>&times;</span>
<div class=”modal-content”><div class=”mySlides”>
<div class=”numbertext”>1 / 4</div>
<img src=”img_nature_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>2 / 4</div>
<img src=”img_fjords_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>3 / 4</div>
<img src=”img_mountains_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>4 / 4</div>
<img src=”img_lights_wide.jpg” style=”width:100%”>
</div>

<a class=”prev” onclick=”plusSlides(-1)”>&#10094;</a>
<a class=”next” onclick=”plusSlides(1)”>&#10095;</a>

<div class=”caption-container”>
<p id=”caption”></p>
</div>

<div class=”column”>
<img class=”demo” src=”img1.jpg” onclick=”currentSlide(1)” alt=”Nature”>
</div>

<div class=”column”>
<img class=”demo” src=”img2.jpg” onclick=”currentSlide(2)” alt=”Trolltunga”>
</div>

<div class=”column”>
<img class=”demo” src=”img3.jpg” onclick=”currentSlide(3)” alt=”Mountains”>
</div>

<div class=”column”>
<img class=”demo” src=”img4.jpg” onclick=”currentSlide(4)” alt=”Lights”>
</div>
</div>
</div>


Step 2) Add CSS:

CODE:

.row > .column {
padding: 0 8px;
}.row:after {
content: “”;
display: table;
clear: both;
}.column {
float: left;
width: 25%;
}/* The Modal (background) */
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
}/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}

.mySlides {
display: none;
}

/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}

/* Position the “next button” to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

.caption-container {
text-align: center;
background-color: black;
padding: 2px 16px;
color: white;
}

img.demo {
opacity: 0.6;
}

.active,
.demo:hover {
opacity: 1;
}

img.hover-shadow {
transition: 0.3s
}

.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}


Step 3) Add JavaScript:

CODE:

<script>
function openModal() {
document.getElementById(‘myModal’).style.display = “block”;
}function closeModal() {
document.getElementById(‘myModal’).style.display = “none”;
}var slideIndex = 1;
showSlides(slideIndex);function plusSlides(n) {
showSlides(slideIndex += n);
}function currentSlide(n) {
showSlides(slideIndex = n);
}function showSlides(n) {
var i;
var slides = document.getElementsByClassName(“mySlides”);
var dots = document.getElementsByClassName(“demo”);
var captionText = document.getElementById(“caption”);
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = “none”;
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(” active”, “”);
}
slides[slideIndex-1].style.display = “block”;
dots[slideIndex-1].className += ” active”;
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>

Full Code:

<!DOCTYPE html>
<html>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Verdana, sans-serif;
margin: 0;
}

* {
box-sizing: border-box;
}

.row > .column {
padding: 0 8px;
}

.row:after {
content: “”;
display: table;
clear: both;
}

.column {
float: left;
width: 25%;
}

/* The Modal (background) */
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}

/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
}

/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}

.mySlides {
display: none;
}

.cursor {
cursor: pointer
}

/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}

/* Position the “next button” to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

img {
margin-bottom: -4px;
}

.caption-container {
text-align: center;
background-color: black;
padding: 2px 16px;
color: white;
}

.demo {
opacity: 0.6;
}

.active,
.demo:hover {
opacity: 1;
}

img.hover-shadow {
transition: 0.3s
}

.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
</style>
<body>

<h2 style=”text-align:center”>Lightbox</h2>

<div class=”row”>
<div class=”column”>
<img src=”img_nature.jpg” style=”width:100%” onclick=”openModal();currentSlide(1)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_fjords.jpg” style=”width:100%” onclick=”openModal();currentSlide(2)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_mountains.jpg” style=”width:100%” onclick=”openModal();currentSlide(3)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_lights.jpg” style=”width:100%” onclick=”openModal();currentSlide(4)” class=”hover-shadow cursor”>
</div>
</div>

<div id=”myModal” class=”modal”>
<span class=”close cursor” onclick=”closeModal()”>&times;</span>
<div class=”modal-content”>

<div class=”mySlides”>
<div class=”numbertext”>1 / 4</div>
<img src=”img_nature_wide.jpg” style=”width:100%”>
</div>

<div class=”mySlides”>
<div class=”numbertext”>2 / 4</div>
<img src=”img_fjords_wide.jpg” style=”width:100%”>
</div>

<div class=”mySlides”>
<div class=”numbertext”>3 / 4</div>
<img src=”img_mountains_wide.jpg” style=”width:100%”>
</div>

<div class=”mySlides”>
<div class=”numbertext”>4 / 4</div>
<img src=”img_lights_wide.jpg” style=”width:100%”>
</div>

<a class=”prev” onclick=”plusSlides(-1)”>&#10094;</a>
<a class=”next” onclick=”plusSlides(1)”>&#10095;</a>

<div class=”caption-container”>
<p id=”caption”></p>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_nature_wide.jpg” style=”width:100%” onclick=”currentSlide(1)” alt=”Nature and sunrise”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_fjords_wide.jpg” style=”width:100%” onclick=”currentSlide(2)” alt=”Trolltunga, Norway”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_mountains_wide.jpg” style=”width:100%” onclick=”currentSlide(3)” alt=”Mountains and fjords”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_lights_wide.jpg” style=”width:100%” onclick=”currentSlide(4)” alt=”Northern Lights”>
</div>
</div>
</div>

<script>
function openModal() {
document.getElementById(‘myModal’).style.display = “block”;
}

function closeModal() {
document.getElementById(‘myModal’).style.display = “none”;
}

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
showSlides(slideIndex += n);
}

function currentSlide(n) {
showSlides(slideIndex = n);
}

function showSlides(n) {
var i;
var slides = document.getElementsByClassName(“mySlides”);
var dots = document.getElementsByClassName(“demo”);
var captionText = document.getElementById(“caption”);
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = “none”;
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(” active”, “”);
}
slides[slideIndex-1].style.display = “block”;
dots[slideIndex-1].className += ” active”;
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>

</body>
</html>


CLICK HERE TO VIEW FUNCTIONING MODAL IMAGE GALLERY Continue reading “CSS & Javascript Modal Image Gallery”

CSS & Javascript Modal Image Gallery

Learn how to create a modal image gallery (lightbox) with CSS and JavaScript.


Lightbox (Modal Image Gallery)

 


Create A Lightbox

Step 1) Add HTML:

CODE:

<div class=”row”>
<div class=”column”>
<img src=”img1.jpg” onclick=”openModal();currentSlide(1)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img2.jpg” onclick=”openModal();currentSlide(2)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img3.jpg” onclick=”openModal();currentSlide(3)” class=”hover-shadow”>
</div>
<div class=”column”>
<img src=”img4.jpg” onclick=”openModal();currentSlide(4)” class=”hover-shadow”>
</div>
</div><div id=”myModal” class=”modal”>
<span class=”close cursor” onclick=”closeModal()”>&times;</span>
<div class=”modal-content”><div class=”mySlides”>
<div class=”numbertext”>1 / 4</div>
<img src=”img_nature_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>2 / 4</div>
<img src=”img_fjords_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>3 / 4</div>
<img src=”img_mountains_wide.jpg” style=”width:100%”>
</div><div class=”mySlides”>
<div class=”numbertext”>4 / 4</div>
<img src=”img_lights_wide.jpg” style=”width:100%”>
</div>
<a class=”prev” onclick=”plusSlides(-1)”>&#10094;</a>
<a class=”next” onclick=”plusSlides(1)”>&#10095;</a>
<div class=”caption-container”>
<p id=”caption”></p>
</div>
<div class=”column”>
<img class=”demo” src=”img1.jpg” onclick=”currentSlide(1)” alt=”Nature”>
</div>
<div class=”column”>
<img class=”demo” src=”img2.jpg” onclick=”currentSlide(2)” alt=”Trolltunga”>
</div>
<div class=”column”>
<img class=”demo” src=”img3.jpg” onclick=”currentSlide(3)” alt=”Mountains”>
</div>
<div class=”column”>
<img class=”demo” src=”img4.jpg” onclick=”currentSlide(4)” alt=”Lights”>
</div>
</div>
</div>

Step 2) Add CSS:

CODE:

.row > .column {
padding: 0 8px;
}.row:after {
content: “”;
display: table;
clear: both;
}.column {
float: left;
width: 25%;
}/* The Modal (background) */
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
}/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
.mySlides {
display: none;
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the “next button” to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
.caption-container {
text-align: center;
background-color: black;
padding: 2px 16px;
color: white;
}
img.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
img.hover-shadow {
transition: 0.3s
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}

Step 3) Add JavaScript:

CODE:

<script>
function openModal() {
document.getElementById(‘myModal’).style.display = “block”;
}function closeModal() {
document.getElementById(‘myModal’).style.display = “none”;
}var slideIndex = 1;
showSlides(slideIndex);function plusSlides(n) {
showSlides(slideIndex += n);
}function currentSlide(n) {
showSlides(slideIndex = n);
}function showSlides(n) {
var i;
var slides = document.getElementsByClassName(“mySlides”);
var dots = document.getElementsByClassName(“demo”);
var captionText = document.getElementById(“caption”);
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = “none”;
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(” active”, “”);
}
slides[slideIndex-1].style.display = “block”;
dots[slideIndex-1].className += ” active”;
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
Full Code:

<!DOCTYPE html>
<html>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<style>
body {
font-family: Verdana, sans-serif;
margin: 0;
}
* {
box-sizing: border-box;
}
.row > .column {
padding: 0 8px;
}
.row:after {
content: “”;
display: table;
clear: both;
}
.column {
float: left;
width: 25%;
}
/* The Modal (background) */
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: black;
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
width: 90%;
max-width: 1200px;
}
/* The Close Button */
.close {
color: white;
position: absolute;
top: 10px;
right: 25px;
font-size: 35px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #999;
text-decoration: none;
cursor: pointer;
}
.mySlides {
display: none;
}
.cursor {
cursor: pointer
}
/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-top: -50px;
color: white;
font-weight: bold;
font-size: 20px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
-webkit-user-select: none;
}
/* Position the “next button” to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
img {
margin-bottom: -4px;
}
.caption-container {
text-align: center;
background-color: black;
padding: 2px 16px;
color: white;
}
.demo {
opacity: 0.6;
}
.active,
.demo:hover {
opacity: 1;
}
img.hover-shadow {
transition: 0.3s
}
.hover-shadow:hover {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)
}
</style>
<body>
<h2 style=”text-align:center”>Lightbox</h2>
<div class=”row”>
<div class=”column”>
<img src=”img_nature.jpg” style=”width:100%” onclick=”openModal();currentSlide(1)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_fjords.jpg” style=”width:100%” onclick=”openModal();currentSlide(2)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_mountains.jpg” style=”width:100%” onclick=”openModal();currentSlide(3)” class=”hover-shadow cursor”>
</div>
<div class=”column”>
<img src=”img_lights.jpg” style=”width:100%” onclick=”openModal();currentSlide(4)” class=”hover-shadow cursor”>
</div>
</div>
<div id=”myModal” class=”modal”>
<span class=”close cursor” onclick=”closeModal()”>&times;</span>
<div class=”modal-content”>
<div class=”mySlides”>
<div class=”numbertext”>1 / 4</div>
<img src=”img_nature_wide.jpg” style=”width:100%”>
</div>
<div class=”mySlides”>
<div class=”numbertext”>2 / 4</div>
<img src=”img_fjords_wide.jpg” style=”width:100%”>
</div>
<div class=”mySlides”>
<div class=”numbertext”>3 / 4</div>
<img src=”img_mountains_wide.jpg” style=”width:100%”>
</div>
<div class=”mySlides”>
<div class=”numbertext”>4 / 4</div>
<img src=”img_lights_wide.jpg” style=”width:100%”>
</div>
<a class=”prev” onclick=”plusSlides(-1)”>&#10094;</a>
<a class=”next” onclick=”plusSlides(1)”>&#10095;</a>
<div class=”caption-container”>
<p id=”caption”></p>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_nature_wide.jpg” style=”width:100%” onclick=”currentSlide(1)” alt=”Nature and sunrise”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_fjords_wide.jpg” style=”width:100%” onclick=”currentSlide(2)” alt=”Trolltunga, Norway”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_mountains_wide.jpg” style=”width:100%” onclick=”currentSlide(3)” alt=”Mountains and fjords”>
</div>
<div class=”column”>
<img class=”demo cursor” src=”img_lights_wide.jpg” style=”width:100%” onclick=”currentSlide(4)” alt=”Northern Lights”>
</div>
</div>
</div>
<script>
function openModal() {
document.getElementById(‘myModal’).style.display = “block”;
}
function closeModal() {
document.getElementById(‘myModal’).style.display = “none”;
}
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName(“mySlides”);
var dots = document.getElementsByClassName(“demo”);
var captionText = document.getElementById(“caption”);
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = “none”;
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(” active”, “”);
}
slides[slideIndex-1].style.display = “block”;
dots[slideIndex-1].className += ” active”;
captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>
</body>
</html>


CLICK HERE TO VIEW FUNCTIONING MODAL IMAGE GALLERY Continue reading “CSS & Javascript Modal Image Gallery”

CSS and Javascript Responsive Modal Image

Learn how to create responsive Modal Images with CSS and JavaScript.


Modal Image

A modal is a dialog box/popup window that is displayed on top of the current page.


Step 1) Add HTML:

CODE:

<!– Trigger the Modal –>
<img id=”myImg” src=”img_fjords.jpg” alt=”Trolltunga, Norway” width=”300″ height=”200″><!– The Modal –>
<div id=”myModal” class=”modal”><!– The Close Button –>
<span class=”close” onclick=”document.getElementById(‘myModal’).style.display=’none'”>&times;</span><!– Modal Content (The Image) –>
<img class=”modal-content” id=”img01″>

<!– Modal Caption (Image Text) –>
<div id=”caption”></div>
</div>


Step 2) Add CSS:

CODE:

/* Style the Image Used to Trigger the Modal */
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}#myImg:hover {opacity: 0.7;}/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}/* Modal Content (Image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}

/* Caption of Modal Image (Image Text) – Same Width as the Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}

/* Add Animation – Zoom in the Modal */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}

@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}

/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}

.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}


Step 3) Add JavaScript:

CODE:

// Get the modal
var modal = document.getElementById(‘myModal’);// Get the image and insert it inside the modal – use its “alt” text as a caption
var img = document.getElementById(‘myImg’);
var modalImg = document.getElementById(“img01”);
var captionText = document.getElementById(“caption”);
img.onclick = function(){
modal.style.display = “block”;
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}// Get the <span> element that closes the modal
var span = document.getElementsByClassName(“close”)[0];// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}

FUll COde:

<!DOCTYPE html>
<html>
<head>
<style>
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}

/* Caption of Modal Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}

/* Add Animation */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}

@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}

/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}

.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
</style>
</head>
<body>

<h2>Image Modal</h2>
<p>In this example, we use CSS to create a modal (dialog box) that is hidden by default.</p>
<p>We use JavaScript to trigger the modal and to display the current image inside the modal when it is clicked on. Also note that we use the value from the image’s “alt” attribute as an image caption text inside the modal.</p>

<img id=”myImg” src=”img_fjords.jpg” alt=”Trolltunga, Norway” width=”300″ height=”200″>

<!– The Modal –>
<div id=”myModal” class=”modal”>
<span class=”close”>&times;</span>
<img class=”modal-content” id=”img01″>
<div id=”caption”></div>
</div>

<script>
// Get the modal
var modal = document.getElementById(‘myModal’);

// Get the image and insert it inside the modal – use its “alt” text as a caption
var img = document.getElementById(‘myImg’);
var modalImg = document.getElementById(“img01”);
var captionText = document.getElementById(“caption”);
img.onclick = function(){
modal.style.display = “block”;
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName(“close”)[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}
</script>

</body>
</html>


CLICK HERE TO VIEW WORKING IMAGE MODAL Continue reading “CSS and Javascript Responsive Modal Image”

How to Create a Modal Box

How To Create a Modal Box

A modal is a dialog box/popup window that is displayed on top of the current page:


Step 1) Add HTML:

CODE:

<!– Trigger/Open The Modal –>
<button id=”myBtn”>Open Modal</button><!– The Modal –>
<div id=”myModal” class=”modal”><!– Modal content –>
<div class=”modal-content”>
<span class=”close”>&times;</span>
<p>Some text in the Modal..</p>
</div></div>


Step 2) Add CSS:

CODE:

/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}/* Modal Content/Box */
.modal-content {
background-color: #fefefe;
margin: 15% auto; /* 15% from the top and centered */
padding: 20px;
border: 1px solid #888;
width: 80%; /* Could be more or less, depending on screen size */
}/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}


Step 3) Add JavaScript:

CODE:

// Get the modal
var modal = document.getElementById(‘myModal’);// Get the button that opens the modal
var btn = document.getElementById(“myBtn”);// Get the <span> element that closes the modal
var span = document.getElementsByClassName(“close”)[0];// When the user clicks on the button, open the modal
btn.onclick = function() {
modal.style.display = “block”;
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = “none”;
}
}


Add Header and Footer

Add a class for modal-header, modal-body and modal-footer:

CODE:

<!– Modal content –>
<div class=”modal-content”>
<div class=”modal-header”>
<span class=”close”>&times;</span>
<h2>Modal Header</h2>
</div>
<div class=”modal-body”>
<p>Some text in the Modal Body</p>
<p>Some other text…</p>
</div>
<div class=”modal-footer”>
<h3>Modal Footer</h3>
</div>
</div>

Style the modal header, body and footer, and add animation (slide in the modal):

CODE:

/* Modal Header */
.modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}/* Modal Body */
.modal-body {padding: 2px 16px;}/* Modal Footer */
.modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
from {top: -300px; opacity: 0}
to {top: 0; opacity: 1}
}

@keyframes animatetop {
from {top: -300px; opacity: 0}
to {top: 0; opacity: 1}
}


FULL CODE:
<!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}

/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}

.modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}
</style>
</head>
<body>

<h2>Animated Modal with Header and Footer</h2>

<!– Trigger/Open The Modal –>
<button id=”myBtn”>Open Modal</button>

<!– The Modal –>
<div id=”myModal” class=”modal”>

<!– Modal content –>
<div class=”modal-content”>
<div class=”modal-header”>
<span class=”close”>&times;</span>
<h2>Modal Header</h2>
</div>
<div class=”modal-body”>
<p>Some text in the Modal Body</p>
<p>Some other text…</p>
</div>
<div class=”modal-footer”>
<h3>Modal Footer</h3>
</div>
</div>

</div>

<script>
// Get the modal
var modal = document.getElementById(‘myModal’);

// Get the button that opens the modal
var btn = document.getElementById(“myBtn”);

// Get the <span> element that closes the modal
var span = document.getElementsByClassName(“close”)[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = “block”;
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = “none”;
}
}
</script>

</body>
</html>


Bottom Modal (“Bottom sheets”)

An example on how to create a full-width modal that slides in from the bottom:

CODE:

<!DOCTYPE html>
<html>
<head>
<style>
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
-webkit-animation-name: fadeIn; /* Fade in the background */
-webkit-animation-duration: 0.4s;
animation-name: fadeIn;
animation-duration: 0.4s
}

/* Modal Content */
.modal-content {
position: fixed;
bottom: 0;
background-color: #fefefe;
width: 100%;
-webkit-animation-name: slideIn;
-webkit-animation-duration: 0.4s;
animation-name: slideIn;
animation-duration: 0.4s
}

/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}

.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}

.modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}

.modal-body {padding: 2px 16px;}

.modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}

/* Add Animation */
@-webkit-keyframes slideIn {
from {bottom: -300px; opacity: 0}
to {bottom: 0; opacity: 1}
}

@keyframes slideIn {
from {bottom: -300px; opacity: 0}
to {bottom: 0; opacity: 1}
}

@-webkit-keyframes fadeIn {
from {opacity: 0}
to {opacity: 1}
}

@keyframes fadeIn {
from {opacity: 0}
to {opacity: 1}
}
</style>
</head>
<body>

<h2>Bottom Modal</h2>

<!– Trigger/Open The Modal –>
<button id=”myBtn”>Open Modal</button>

<!– The Modal –>
<div id=”myModal” class=”modal”>

<!– Modal content –>
<div class=”modal-content”>
<div class=”modal-header”>
<span class=”close”>&times;</span>
<h2>Modal Header</h2>
</div>
<div class=”modal-body”>
<p>Some text in the Modal Body</p>
<p>Some other text…</p>
</div>
<div class=”modal-footer”>
<h3>Modal Footer</h3>
</div>
</div>

</div>

<script>
// Get the modal
var modal = document.getElementById(‘myModal’);

// Get the button that opens the modal
var btn = document.getElementById(“myBtn”);

// Get the <span> element that closes the modal
var span = document.getElementsByClassName(“close”)[0];

// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = “block”;
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = “none”;
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = “none”;
}
}
</script>

</body>
</html>


VIEW WORKING MODALS HERE

Continue reading “How to Create a Modal Box”