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,138 |
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 |
SMITE Ward Icon | 3,236 Kb |
Responsive Mixed with Absolute | 2,495 Kb |
Header logo that changes | 2,031 Kb |
Aaronmarino.com v2 styles | 2,863 Kb |
Promise example | 2,343 Kb |
Tile with special tiles experiment | 1,952 Kb |
Fruit Stripe Background | 2,758 Kb |
Donatello Sprite | 2,452 Kb |
Hi-rez logo | 5,938 Kb |
ExamplesEdit | 1,592 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 |
Animate a paper plane along an SVG path, looking ahead | PotatoDie | 3,734 Kb |
Ripples in water | Nobitagit | 2,704 Kb |
Twitch API | Coderpilot | 3,412 Kb |
CSS Colors | Alexpate | 2,232 Kb |
CSS Patterns | Alyda | 3,953 Kb |
Slide like Mailbox | Hmps | 3,758 Kb |
Content Changer | Cliffpyles | 4,538 Kb |
CSS Parent Selector | Tomhodgins | 2,143 Kb |
Scroll to top button | DominicFrancois | 3,743 Kb |
Blog | Rottingroom | 1,430 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!