FocalCenter.js for jQuery

Developer
Size
3,462 Kb
Views
12,144

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 Previews

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();
});
FocalCenter.js for jQuery - Script Codes
FocalCenter.js for jQuery - Script Codes
Home Page Home
Developer Coran Spicer
Username cgspicer
Uploaded October 15, 2022
Rating 3
Size 3,462 Kb
Views 12,144
Do you need developer help for FocalCenter.js for jQuery?

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!

Coran Spicer (cgspicer) 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!