FocalCenter.js for jQuery
How do I make an focalcenter.js for jquery?
A jQuery plugin that stores an array of elements and adds a class to the element that is center-most in the viewport. Useful for drawing user attention to the center-most article in a loop, for instance.. What is a focalcenter.js for jquery? How do you make a focalcenter.js for jquery? This script and codes were developed by Coran Spicer on 15 October 2022, Saturday.
FocalCenter.js for jQuery - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>focalCenter.js for jQuery</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <article class="post first"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post second"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post third"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post fourth"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post fourth"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post fourth"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post fourth"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article> <article class="post fourth"> <header> <h3>Some Post</h3> </header> <section> <p>Some sort of content and ipsum. Bacon ipsum dolor sit amet doner short loin andouille ball tip tongue pastrami. Corned beef spare ribs shoulder pastrami doner bresaola sausage ribeye beef frankfurter meatball sirloin cow flank pig. Salami strip steak sirloin drumstick ribeye meatloaf. Cow turducken flank shoulder t-bone hamburger. T-bone short loin pastrami brisket beef ribs ball tip. Pork loin turducken jowl, short ribs tail corned beef andouille pork chop jerky.</p> </section> </article>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
FocalCenter.js for jQuery - Script Codes CSS Codes
body { padding-top: 100px; background: rgba( 72, 123, 127, .8 ); }
article.post { margin: 60px 10px; -webkit-transition: background 1s, opacity 1.3s; -moz-transition: background 1s, opacity 1.3s; transition: background 1s, opacity 1.3s; padding: 20px 10px; border-radius: 5px; opacity: .5;
}
article.post header h3 { font-weight:bold; text-indent: 10px; color: rgb( 1, 29, 36 ); }
article.post section p { padding: 20px; color: rgb( 1, 29, 36 ); }
article.post.focal-center { background: rgb( 255, 190, 141 ); box-shadow: 2px 2px 9px rgb( 1, 29, 36 ); opacity: 1;
}
article.post.focal-center h3 { color: rgb( 170, 44, 48 ); }
article.post.focal-center p { color: rgb( 88, 0, 34); }
FocalCenter.js for jQuery - Script Codes JS Codes
(function( $ ){ /** * focalCenter.js * A jQuery plugin that takes an array of elements and assigns a class to the element nearest the viewport's center * http://www.codekaiju.com * * Copyright 2013, Coran Spicer * Free to use under the MIT license. * * Date: Mon Feb 11 2013 */ var methods = { init : function( options ) { var settings = $.extend( { 'direction' : 'vertical', 'classToAssign' : 'focal-center', 'relativeContainer' : 'window' //unsupported stub }, options); $this = $(this); var $container = settings.relativeContainer == 'window' ? $(window) : $this.closest( $( settings.relativeContainer ) ); var minWidth = $container.scrollLeft(); var maxWidth = $container.width(); var centerX = (maxWidth + minWidth) / 2; var minHeight = $container.scrollTop(); var maxHeight = $container.height(); var centerY = (maxHeight + minHeight)/2; var focalPoints = []; $this.each( function(target) { self = this; self.fromCenterX = Math.abs( centerX - ( $(self).offset().left + $(self).width() / 2 ) + minWidth / 2 ); self.fromCenterY = Math.abs( centerY - ( $(self).offset().top + $(self).height() / 2 ) + minHeight / 2 ); focalPoints.push(self); }); function assignClasses() { for ( var f = 0; f < focalPoints.length; f++ ) { $( focalPoints[f] ).removeClass( settings.classToAssign ); } var lastFocalPoint = focalPoints.length - 1; $( focalPoints[ lastFocalPoint ] ).addClass( settings.classToAssign ); } function getDistances() { minWidth = $container.scrollLeft(); maxWidth = $container.width(); centerX = (maxWidth + minWidth) / 2; minHeight = $container.scrollTop(); maxHeight = $container.height(); centerY = (maxHeight + minHeight) / 2; for ( var i = 0; i < focalPoints.length; i++ ) { self = focalPoints[i]; self.fromCenterX = Math.abs( centerX - ( $(self).offset().left + $(self).width() / 2 ) + minWidth / 2 ); self.fromCenterY = Math.abs( centerY - ( $(self).offset().top + $(self).height() / 2 ) + minHeight / 2 ); } } function sortFocalPoints(){ if ( settings.direction == 'horizontal' ) { focalPoints = focalPoints.sort(function(a, b) { return b.fromCenterY - a.fromCenterY; }); } else if ( settings.direction == 'vertical' ) { focalPoints = focalPoints.sort(function(a, b) { return b.fromCenterY - a.fromCenterY; }); } else { $.error( 'unable to sort against: ' + settings.direction ); } } /* do the work */ $(window).scroll( function() { getDistances(); sortFocalPoints(); assignClasses(); }); getDistances(); sortFocalPoints(); assignClasses(); } }; $.fn.focalCenter = function( method ) { // Method calling logic if ( methods[method] ) { return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); } else if ( typeof method === 'object' || ! method ) { return methods.init.apply( this, arguments ); } else { $.error( 'Method ' + method + ' does not exist on jQuery.focalCenter' ); } };
})( jQuery );
$(document).ready( function(){ $('.post').focalCenter();
});
Developer | Coran Spicer |
Username | cgspicer |
Uploaded | October 15, 2022 |
Rating | 3 |
Size | 3,462 Kb |
Views | 12,144 |
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!
Name | Size |
BuildUp | 3,509 Kb |
Donatello Sprite | 2,452 Kb |
Fully Furnished | 3,613 Kb |
SMITE Ward Icon | 3,236 Kb |
Header logo that changes | 2,031 Kb |
Responsive Mixed with Absolute | 2,495 Kb |
SMITE spinner | 2,508 Kb |
Shattering boxes | 3,390 Kb |
Aaronmarino.com v2 styles | 2,863 Kb |
A Pen by Coran Spicer | 2,815 Kb |
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!
Name | Username | Size |
Material Design-Layout-Principles Practice | Fraina | 2,331 Kb |
My Interests | Anshusaxenaarora | 2,015 Kb |
Loading animation | Codeams | 2,408 Kb |
Free css icon set v2 - one div | Ben_jammin | 0 Kb |
Faces SVG animation | ScavengerFrontend | 2,957 Kb |
LBCA - Mail canvas | Emnbdx | 3,856 Kb |
Commuter Line Tokyu 8500 | Pedox | 7,031 Kb |
Experiment | Toddmoy | 2,849 Kb |
Old calculator | Gnarfugh | 2,815 Kb |
Lightrays v2 | Sinthetyc | 2,903 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!