Skip to content

Commit

Permalink
support custom Before and After labels #28 #49
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaeleidus authored and Raphael Eidus committed May 18, 2017
1 parent 7dc31e5 commit ae9d6e4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -37,7 +37,9 @@ $(window).load(function(){
$(window).load(function(){
$(".twentytwenty-container").twentytwenty({
default_offset_pct: 0.7, // How much of the before image is visible when the page loads
orientation: 'vertical' // Orientation of the before and after images ('horizontal' or 'vertical')
orientation: 'vertical', // Orientation of the before and after images ('horizontal' or 'vertical')
before_label: 'January 2017', // Set a custom before label
after_label: 'March 2017' // Set a custom after label
});
});
```
Expand Down
4 changes: 2 additions & 2 deletions css/twentytwenty-no-compass.css
Expand Up @@ -91,12 +91,12 @@
.twentytwenty-before-label {
opacity: 0; }
.twentytwenty-before-label:before {
content: "Before"; }
content: attr(data-content); }

.twentytwenty-after-label {
opacity: 0; }
.twentytwenty-after-label:before {
content: "After"; }
content: attr(data-content); }

.twentytwenty-horizontal .twentytwenty-before-label:before {
left: 10px; }
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.twentytwenty.js
@@ -1,7 +1,7 @@
(function($){

$.fn.twentytwenty = function(options) {
var options = $.extend({default_offset_pct: 0.5, orientation: 'horizontal'}, options);
var options = $.extend({default_offset_pct: 0.5, orientation: 'horizontal', before_label: 'Before', after_label: 'After'}, options);
return this.each(function() {

var sliderPct = options.default_offset_pct;
Expand All @@ -22,10 +22,10 @@
container.addClass("twentytwenty-container");
beforeImg.addClass("twentytwenty-before");
afterImg.addClass("twentytwenty-after");

var overlay = container.find(".twentytwenty-overlay");
overlay.append("<div class='twentytwenty-before-label'></div>");
overlay.append("<div class='twentytwenty-after-label'></div>");
overlay.append("<div class='twentytwenty-before-label' data-content='"+options.before_label+"'></div>");
overlay.append("<div class='twentytwenty-after-label' data-content='"+options.after_label+"'></div>");

var calcOffset = function(dimensionPct) {
var w = beforeImg.width();
Expand Down
4 changes: 2 additions & 2 deletions scss/twentytwenty-no-compass.scss
Expand Up @@ -143,7 +143,7 @@ $twenty20-label-radius: 2px !default;
&:before {
@extend %label-structure;
@extend %label-text;
content: "Before";
content: attr(data-content);
}
}

Expand All @@ -157,7 +157,7 @@ $twenty20-label-radius: 2px !default;
&:before {
@extend %label-structure;
@extend %label-text;
content: "After";
content: attr(data-content);
}
}

Expand Down
4 changes: 2 additions & 2 deletions scss/twentytwenty.scss
Expand Up @@ -144,7 +144,7 @@ $twenty20-label-radius: 2px !default;
&:before {
@extend %label-structure;
@extend %label-text;
content: "Before";
content: attr(data-content);
}
}

Expand All @@ -158,7 +158,7 @@ $twenty20-label-radius: 2px !default;
&:before {
@extend %label-structure;
@extend %label-text;
content: "After";
content: attr(data-content);
}
}

Expand Down

0 comments on commit ae9d6e4

Please sign in to comment.