mirror of
https://github.com/Rushilwiz/brancher.git
synced 2025-04-20 12:00:16 -04:00
homepage slider stuff
This commit is contained in:
parent
d7b0f491ce
commit
9378e14215
BIN
css/res/black_branch.png
Normal file
BIN
css/res/black_branch.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
css/res/black_branch_big.png
Normal file
BIN
css/res/black_branch_big.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 26 KiB |
BIN
css/res/rainbow_branch_big.png
Normal file
BIN
css/res/rainbow_branch_big.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 33 KiB |
42
css/slider.css
Normal file
42
css/slider.css
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
@import "lesshat";
|
||||||
|
|
||||||
|
.ba-slider {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ba-slider img {
|
||||||
|
width: 100%;
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.resize {
|
||||||
|
position: absolute;
|
||||||
|
top:0;
|
||||||
|
left: 0;
|
||||||
|
height: 100%;
|
||||||
|
width: 50%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.handle { /* Thin line seperator */
|
||||||
|
position:absolute;
|
||||||
|
left:50%;
|
||||||
|
top:0;
|
||||||
|
bottom:0;
|
||||||
|
width:4px;
|
||||||
|
margin-left:-2px;
|
||||||
|
|
||||||
|
background: rgba(0,0,0,.5);
|
||||||
|
cursor: ew-resize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.draggable:after {
|
||||||
|
width: 48px;
|
||||||
|
height: 48px;
|
||||||
|
margin: -24px 0 0 -24px;
|
||||||
|
line-height:48px;
|
||||||
|
font-size:30px;
|
||||||
|
}
|
17
index.html
17
index.html
|
@ -43,8 +43,23 @@
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="hero gradient-border">
|
<div class="hero gradient-border">
|
||||||
<h2><br><br>  You're a<br>brand</h2>
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>...</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="css/slider.css" />
|
||||||
|
<script src="js/slider.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="ba-slider">
|
||||||
|
<img src="css/res/rainbow_branch_big.png" alt="">
|
||||||
|
<div class="resize">
|
||||||
|
<img src="css/res/black_branch_big.png" alt="">
|
||||||
</div>
|
</div>
|
||||||
|
<span class="handle"></span>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="row content">
|
<div class="row content">
|
||||||
<h1 class="sec01">Get Started</h1>
|
<h1 class="sec01">Get Started</h1>
|
||||||
|
|
78
js/slider.js
Normal file
78
js/slider.js
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
// Call & init
|
||||||
|
$(document).ready(function(){
|
||||||
|
$('.ba-slider').each(function(){
|
||||||
|
var cur = $(this);
|
||||||
|
// Adjust the slider
|
||||||
|
var width = cur.width()+'px';
|
||||||
|
cur.find('.resize img').css('width', width);
|
||||||
|
// Bind dragging events
|
||||||
|
drags(cur.find('.handle'), cur.find('.resize'), cur);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update sliders on resize.
|
||||||
|
// Because we all do this: i.imgur.com/YkbaV.gif
|
||||||
|
$(window).resize(function(){
|
||||||
|
$('.ba-slider').each(function(){
|
||||||
|
var cur = $(this);
|
||||||
|
var width = cur.width()+'px';
|
||||||
|
cur.find('.resize img').css('width', width);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function drags(dragElement, resizeElement, container) {
|
||||||
|
|
||||||
|
// Initialize the dragging event on mousedown.
|
||||||
|
dragElement.on('mousedown touchstart', function(e) {
|
||||||
|
|
||||||
|
dragElement.addClass('draggable');
|
||||||
|
resizeElement.addClass('resizable');
|
||||||
|
|
||||||
|
// Check if it's a mouse or touch event and pass along the correct value
|
||||||
|
var startX = (e.pageX) ? e.pageX : e.originalEvent.touches[0].pageX;
|
||||||
|
|
||||||
|
// Get the initial position
|
||||||
|
var dragWidth = dragElement.outerWidth(),
|
||||||
|
posX = dragElement.offset().left + dragWidth - startX,
|
||||||
|
containerOffset = container.offset().left,
|
||||||
|
containerWidth = container.outerWidth();
|
||||||
|
|
||||||
|
// Set limits
|
||||||
|
minLeft = containerOffset + 10;
|
||||||
|
maxLeft = containerOffset + containerWidth - dragWidth - 10;
|
||||||
|
|
||||||
|
// Calculate the dragging distance on mousemove.
|
||||||
|
dragElement.parents().on("mousemove touchmove", function(e) {
|
||||||
|
|
||||||
|
// Check if it's a mouse or touch event and pass along the correct value
|
||||||
|
var moveX = (e.pageX) ? e.pageX : e.originalEvent.touches[0].pageX;
|
||||||
|
|
||||||
|
leftValue = moveX + posX - dragWidth;
|
||||||
|
|
||||||
|
// Prevent going off limits
|
||||||
|
if ( leftValue < minLeft) {
|
||||||
|
leftValue = minLeft;
|
||||||
|
} else if (leftValue > maxLeft) {
|
||||||
|
leftValue = maxLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Translate the handle's left value to masked divs width.
|
||||||
|
widthValue = (leftValue + dragWidth/2 - containerOffset)*100/containerWidth+'%';
|
||||||
|
|
||||||
|
// Set the new values for the slider and the handle.
|
||||||
|
// Bind mouseup events to stop dragging.
|
||||||
|
$('.draggable').css('left', widthValue).on('mouseup touchend touchcancel', function () {
|
||||||
|
$(this).removeClass('draggable');
|
||||||
|
resizeElement.removeClass('resizable');
|
||||||
|
});
|
||||||
|
$('.resizable').css('width', widthValue);
|
||||||
|
}).on('mouseup touchend touchcancel', function(){
|
||||||
|
dragElement.removeClass('draggable');
|
||||||
|
resizeElement.removeClass('resizable');
|
||||||
|
});
|
||||||
|
e.preventDefault();
|
||||||
|
}).on('mouseup touchend touchcancel', function(e){
|
||||||
|
dragElement.removeClass('draggable');
|
||||||
|
resizeElement.removeClass('resizable');
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user