Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
#3, #4 - Code optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdamevin committed Mar 26, 2014
1 parent bb83ed0 commit eac8a5a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 76 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ Easily place your content blocks on top or bottom of the page to scroll.

## Parameters

| Options | Types | Defaults | Others |
| ------------- | ------- | --------- | ---------- |
| mainClass | string | immobilis | Your class |
| css | boolean | ``true`` | ``false`` |
| target | string | top | bottom |
| Options | Types | Defaults | Others |
| ------------- | ------- | --------- | ----------------- |
| itemSelector | string | immobilis | Choose your class |
| css | boolean | ``true`` | ``false`` |
| target | string | "top " | "bottom" |

## Initialize

$(".mobilis").immobilis();

## Changelogs

### 1.2.0

* Options:
* "mainClass" replaced by "itemSelector" ([#3](https://github.com/agenceepsilon/jquery-immobilis/issues/3))
* Code optimisation:
* Code cleaning
* outerHeight(); ([#4](https://github.com/agenceepsilon/jquery-immobilis/issues/4))

### 1.1.1

* innerHeight(); ([#2](https://github.com/agenceepsilon/jquery-immobilis/issues/2))
Expand Down
6 changes: 4 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-immobilis",
"version": "1.1.1",
"version": "1.2.0",
"description": "Easily place your content blocks on top or bottom of the page to scroll.",
"main": "jquery.immobilis.js",
"ignore": [
Expand All @@ -15,7 +15,9 @@
"keywords": [
"jquery",
"scroll",
"fixed"
"fixed",
"header",
"footer"
],
"licenses": [
{
Expand Down
6 changes: 4 additions & 2 deletions immobilis.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"name": "immobilis",
"title": "jQuery Immobilis",
"description": "Easily place your content blocks on top or bottom of the page to scroll.",
"version": "1.1.1",
"version": "1.2.0",
"keywords": [
"jquery",
"scroll",
"fixed"
"fixed",
"header",
"footer"
],
"author": {
"name": "Boris Damevin",
Expand Down
13 changes: 4 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@
.header {
background: dodgerblue;
height: 150px;
border-bottom: solid 1px #CCC;
}
.nav {
background: hotpink;
height: 30px;
border-bottom: solid 1px #CCC;
border-top: dashed 1px #CCC;
border-bottom: dashed 1px #CCC;
}
.main {
background: #9F00FF;
height: 1000px;
border-bottom: solid 1px #CCC;
}
.footer {
background: hotpink;
height: 30px;
border-top: dashed 1px #CCC;
}
.footer2 {
height: 50px;
Expand All @@ -41,10 +39,7 @@
<div class="main">
Main
</div>
<div class="footer mobilis-bottom">
Footer
</div>
<!--<div class="footer2">Footer 2</div>-->
<div class="footer mobilis-bottom">Footer</div>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="jquery.immobilis.js"></script>
<script>
Expand Down
108 changes: 52 additions & 56 deletions jquery.immobilis.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,95 @@
/*!
* jQuery Immobilis v1.1.1 (https://github.com/agenceepsilon/jquery-immobilis)
* jQuery Immobilis v1.2.0 (https://github.com/agenceepsilon/jquery-immobilis)
* Copyright 2014 Agence Epsilon.
* Licensed under MIT (http://www.opensource.org/licenses/mit-license.php)
*/

(function($){
$.fn.immobilis = function(opts){
var defaults = {
mainClass: "immobilis",
itemSelector: "immobilis",
target: "top",
css: true
};

var params = $.extend(defaults, opts);

return this.each(function(){
var $mobilisClass = $(this);
var $initialPosTop = $mobilisClass.offset().top;
var $elem = $(this);
var $initialElemPos = $elem.offset().top;

function cssStyle(){
function cssStyle($reset){
if(params.css){
if(params.target == "top"){
$mobilisClass.css({
"width": "100%",
"position": "fixed",
"top": 0,
"left": 0
});
} else {
$mobilisClass.css({
"width": "100%",
"position": "fixed",
"top": "auto",
"bottom": "0",
"left": 0
});
}
}
}

function cssStyleReset(){
if(params.css){
if(params.target == "top"){
$mobilisClass.css({
"width": "",
"position": "",
"top": "",
"left": ""
});
} else {
$mobilisClass.css({
"width": "",
"position": "",
"top": "",
"bottom": "",
"left": ""
});
if($reset !== false){
if(params.target == "top"){
$elem.css({
"width": "100%",
"position": "fixed",
"top": 0,
"left": 0
});
} else{
$elem.css({
"width": "100%",
"position": "fixed",
"bottom": "0",
"left": 0
});
}
} else{
if(params.target == "top"){
$elem.css({
"width": "",
"position": "",
"top": "",
"left": ""
});
} else{
$elem.css({
"width": "",
"position": "",
"bottom": "",
"left": ""
});
}
}
}
}

function immobilisTop(){
var $scrollTop = $(window).scrollTop();
var $mobilisPos = $mobilisClass.offset().top;
var $mobilisHeight = $($mobilisClass).innerHeight();
var $mobilisPos = $elem.offset().top;
var $elemHeight = $($elem).outerHeight();

if($scrollTop > $mobilisPos){
$mobilisClass.addClass(params.mainClass);
$mobilisClass.next().css("margin-top", $mobilisHeight);
$elem.addClass(params.itemSelector);
$elem.next().css("margin-top", $elemHeight);

cssStyle();
}
if($scrollTop < $initialPosTop){
$mobilisClass.removeClass(params.mainClass);
$mobilisClass.next().css("margin-top", "");
if($scrollTop < $initialElemPos){
$elem.removeClass(params.itemSelector);
$elem.next().css("margin-top", "");

cssStyleReset();
cssStyle(false);
}
}

function immobilisFooter(){
var $scrollTop = $(window).scrollTop();
var $windowHeight = $(window).height();
var $documentHeight = $(document).height();
var $heightGap = $documentHeight - $windowHeight;
var $scrollTop = $(window).scrollTop();
var $mobilisHeight = $($mobilisClass).innerHeight();
var $elemHeight = $($elem).outerHeight();

if($scrollTop >= $heightGap){
$mobilisClass.removeClass(params.mainClass);
$mobilisClass.prev().css("margin-bottom", "");
$elem.removeClass(params.itemSelector);
$elem.prev().css("margin-bottom", "");

cssStyleReset();
cssStyle(false);
} else{
$mobilisClass.addClass(params.mainClass);
$mobilisClass.prev().css("margin-bottom", $mobilisHeight);
$elem.addClass(params.itemSelector);
$elem.prev().css("margin-bottom", $elemHeight);

cssStyle();
}
Expand Down
4 changes: 2 additions & 2 deletions jquery.immobilis.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eac8a5a

Please sign in to comment.