Home / JS

JS

addEventListener basic

<span id="elem">Hello!</span> <script> elem.addEventListener('click',function(){ alert('hello'); }); </script> Hits: 58

Read More »

smartupworld | Creating a Notification through JavaScript and blink it every 1.5 second

Style .notification { position: fixed; z-index: 1000; padding: 5px; border: 1px solid black; font-size: 20px; background: white; text-align: center; } .welcome { background: #b80000; color: yellow; } JS – function showNotification({top=0,right=0,background="#ededed",color="blue",html=""}){ let notification = document.createElement('div'); notification.className = "notification"; notification.innerHTML = html; notification.style.top = top+"px"; notification.style.color = color; notification.style.right = right+"px"; …

Read More »

Search Results Web results How To Create a Scroll Back To Top Button

window.onscroll = function(){scrollFunction()}; let scroll = document.getElementById(‘scroll-top-btn’); if(scroll){ scroll.style.display = “none”; } function scrollFunction(){ if(document.body.scrollTop > 180|| document.documentElement.scrollTop > 180){ //document.getElementById(‘menu’).style.cssText = “position: fixed; width: 100%; z-index: 9; background: #fff; top: 0;”; if(document.getElementById(‘menu’).classList.contains(‘scroll-menu-active’)==false){ //document.getElementById(‘menu’).classList.add(‘scroll-menu-active’); document.getElementById(‘menu’).className += ” “+”scroll-menu-active”; } }else{ document.getElementById(‘menu’).classList.remove(‘scroll-menu-active’) } if(document.body.scrollTop > 20|| document.documentElement.scrollTop > 20){ document.getElementById(‘scroll-top-btn’).style.display = …

Read More »