Table scroll shadows

Developer
Size
3,691 Kb
Views
20,240

How do I make an table scroll shadows?

What is a table scroll shadows? How do you make a table scroll shadows? This script and codes were developed by Hawcubite on 14 December 2022, Wednesday.

Table scroll shadows Previews

Table scroll shadows - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Table scroll shadows</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Table scroll shadows</h1>
<div class="wrapper"> <p>Here is a small workaround for indicating if a table is wider than its surrounding (scrollable) container. This is handy if a browser isn't showing scrollbars by default, i.e. on mobile devices.</p> <p>Right now there are no reliable ways to achieve this effect in CSS, so we need JS.</p> <p>Tables receive inner shadows on the sides which are not (or nearly) scrolled to the end. The shadow width is defined in the CSS class 'table-shadow'. The scroll distance needed to show the shadow in full opacity is also inherited by this value.</p> <p>It doesn't matter which size the table has:</p> <div class="table-wrapper"> <table style="width:500px" class="table"> <tr> <td>fooooooooooooooooooooooooooooooo</td> <td>fooooooooooooooooooooooooooooooo</td> <td>fooooooooooooooooooooooooooooooo</td> </tr> <tr> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaar</td> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaar</td> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaar</td> </tr> <tr> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz</td> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz</td> <td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz</td> </tr> </table> </div> <div class="table-wrapper" style="width:300px"> <table class="table"> <tr><td>fooooooooooooooooooooooooooooooooooooooooooo</td></tr> <tr><td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar</td></tr> <tr><td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz</td></tr> </table> </div> <p>If the table is smaller than the wrapper, there is no shadow shown. The shadow elements are already there, so there is no problem with dynamically filling the table.*</p> <div class="table-wrapper" style="width:300px"> <table class="table"> <tr><td>fooooooooooooooooooooooooooooooo</td></tr> <tr><td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaar</td></tr> <tr><td>baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz</td></tr> </table> </div> <p>*I do not claim for this to be bug free. Example: Right now, after inserting content to the table when it's already rendered, the shadow won't update	until you scroll.</p> <p>Also, this could easily be done in Vanilla JS (right now it's dependent on jQuery) and isn't really optimized in any way (although it should work cross browser).</p> <small>P.S.: Isn't that a beautiful gradient in the background?</small> <footer><em>Something to say? Tell me: <a href="https://twitter.com/hawcubites" target="_blank">@hawcubites</a></em></footer>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Table scroll shadows - Script Codes CSS Codes

@font-face { font-family: 'Vampiro One'; font-style: normal; font-weight: 400; src: local('Vampiro One'), local('VampiroOne-Regular'), url(https://fonts.gstatic.com/s/vampiroone/v7/Ho2Xld8UbQyBA8XLxF1_NYbN6UDyHWBl620a-IRfuBk.woff) format('woff');
}
* { box-sizing: border-box; }
body { background: lavender; background: linear-gradient(to bottom right, #00eaff, #c600ff) fixed; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
h1 { min-width: 600px; margin: 60px 0; text-align: center; color: white; font-family: "Vampiro One","Lato","Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif; font-size: 4rem; font-weight: 300; text-shadow: 0 0 20px rgba(0,0,0,.5);
}
.wrapper { width: 600px; margin: 40px auto; padding: 30px; background: white; border-radius: 8px; box-shadow: 0 0 80px rgba(0,0,0,.2);
}
.wrapper > p:first-child { margin-top: 0;
}
.wrapper > p:last-child { margin-bottom: 0;
}
footer { margin-top: 40px; text-align: center;
}
.table-wrapper { margin: 40px auto;
}
.table-wrapper,
.table-inner-wrapper { position: relative; overflow: auto;
}
.table-shadow { position: absolute; top: 0; bottom: 0; height: 100%; width: 50px; z-index: 1; pointer-events: none; opacity: 0;
}
.shadow-left { left: 0; background-image: linear-gradient( to left, rgba(255,255,255,0), rgba(255,255,255,1) );
}
.shadow-right { right: 0; background-image: linear-gradient( to right, rgba(255,255,255,0), rgba(255,255,255,1) );
}

Table scroll shadows - Script Codes JS Codes

$(".table-wrapper").each(function() { var wrapper = $(this); /* Erstellt die nötigen DIVs */ var tableHtml = wrapper.html(); wrapper.html("<div class='table-shadow shadow-left'></div><div class='table-inner-wrapper'>" + tableHtml + "</div><div class='table-shadow shadow-right'></div>"); var innerWrapper = wrapper.children(".table-inner-wrapper"); var shadowLeft = wrapper.children(".shadow-left"); var shadowRight = wrapper.children(".shadow-right"); var tableScrollLeft = getScrollPosition(innerWrapper,"left"); var tableScrollRight = getScrollPosition(innerWrapper,"right"); /* Setzt die initiale Transparenz der Schatten */ setScrollOpacity( shadowLeft, tableScrollLeft ); setScrollOpacity( shadowRight, tableScrollRight ); /* Setzt die Transparenz wärend des Scrollens passend zur Position */ innerWrapper.scroll(function() { var innerWrapper = $(this); var tableScrollLeft = getScrollPosition(innerWrapper,"left"); var tableScrollRight = getScrollPosition(innerWrapper,"right"); setScrollOpacity( shadowLeft, tableScrollLeft ); setScrollOpacity( shadowRight, tableScrollRight ); }); /* Liefert den Scrollabstand zur übergebenen Seite des Tabellenrahmens */ function getScrollPosition( innerWrapper, side ) { switch(side) { case "left": return innerWrapper.scrollLeft(); case "right": return tableScrollRight = innerWrapper.children("table").width() - innerWrapper.width() - innerWrapper.scrollLeft(); default: return false; } } /* Setzt die Transparenz der Schatten */ function setScrollOpacity( shadowElem, scrollPosition ) { var shadowElemWidth = shadowElem.width(); /* Der Schatten wird nur sichtbar, wenn ein Scrollabstand zur jeweiligen Seite vorhanden ist */ if((scrollPosition / shadowElemWidth) <= 0 ) { shadowElem.css({ opacity: 0 }); } else if( scrollPosition <= shadowElemWidth ) { var opacity = scrollPosition / shadowElemWidth; shadowElem.css({ opacity: opacity }); } else { if( shadowElem.css("opacity") != 1 ) { shadowElem.css({ opacity: 1 }); } } }
});
Table scroll shadows - Script Codes
Table scroll shadows - Script Codes
Home Page Home
Developer Hawcubite
Username hawcubite
Uploaded December 14, 2022
Rating 3
Size 3,691 Kb
Views 20,240
Do you need developer help for Table scroll shadows?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Hawcubite (hawcubite) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!