Skip to content
This repository has been archived by the owner on May 5, 2021. It is now read-only.

Commit

Permalink
Browser testing and fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbitron committed Sep 2, 2014
1 parent 93b64e0 commit 182140b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ slider.start();
|get(attribute)|Get an attribute value (attributes are mostly used internally)|
|set(attribute, value)|Set an attribute. Can be useful for storing custom data|

## Browsers

Ideal Image Slider has been tested on:

* Chrome
* Firefox
* Safari (Desktop + Mobile)
* Opera
* IE9

## Contribute

So you want to help out? That's awesome. Here is how you can do it:
Expand Down
15 changes: 8 additions & 7 deletions ideal-image-slider.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@

/* Slide effect */
.iis-effect-slide .iis-slide {
-webkit-transition-property: all;
-moz-transition-property: all;
-o-transition-property: all;
transition-property: all;
opacity: 0;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
-webkit-transition-timing-function: ease-out;
-moz-transition-timing-function: ease-out;
-o-transition-timing-function: ease-out;
Expand All @@ -41,6 +42,7 @@
-ms-transform: translateX(0%);
transform: translateX(0%);
}
.iis-effect-slide .iis-current-slide { opacity: 1; }
.iis-effect-slide .iis-previous-slide {
-webkit-transform: translateX(-100%);
-ms-transform: translateX(-100%);
Expand All @@ -51,9 +53,8 @@
-ms-transform: translateX(100%);
transform: translateX(100%);
}
.iis-effect-slide .iis-previous-slide { z-index: 1; }
.iis-effect-slide .iis-next-slide { z-index: 2; }
.iis-effect-slide .iis-current-slide { z-index: 3; }
.iis-direction-previous.iis-effect-slide .iis-next-slide,
.iis-direction-next.iis-effect-slide .iis-previous-slide { opacity: 1; }

/* Fade effect */
.iis-effect-fade .iis-slide {
Expand Down
59 changes: 43 additions & 16 deletions ideal-image-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,24 @@ var IdealImageSlider = (function() {
var _loadImg = function(slide, callback) {
if(!slide.style.backgroundImage){
var img = new Image();
img.src = slide.dataset.src;
img.setAttribute('src', slide.getAttribute('data-src'));
img.onload = function() {
slide.style.backgroundImage = 'url('+ slide.dataset.src +')';
slide.style.backgroundImage = 'url('+ slide.getAttribute('data-src') +')';
if(typeof(callback) === 'function') callback(this);
};
}
};

var _isHighDPI = function(){
return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 124dpi), only screen and (min-resolution: 1.3dppx), only screen and (min-resolution: 48.8dpcm)').matches ||
window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)').matches)) ||
(window.devicePixelRatio && window.devicePixelRatio > 1.3));
var mediaQuery = "(-webkit-min-device-pixel-ratio: 1.5),\
(min--moz-device-pixel-ratio: 1.5),\
(-o-min-device-pixel-ratio: 3/2),\
(min-resolution: 1.5dppx)";
if (window.devicePixelRatio > 1)
return true;
if (window.matchMedia && window.matchMedia(mediaQuery).matches)
return true;
return false;
}


Expand Down Expand Up @@ -110,7 +116,9 @@ var IdealImageSlider = (function() {
nextSlide: 'iis-next-slide',
previousNav: 'iis-previous-nav',
nextNav: 'iis-next-nav',
animating: 'iis-is-animating'
animating: 'iis-is-animating',
directionPrevious: 'iis-direction-previous',
directionNext: 'iis-direction-next'
},
onInit: function(){},
onStart: function(){},
Expand Down Expand Up @@ -155,17 +163,26 @@ var IdealImageSlider = (function() {
}
}

_deepExtend(slideEl.dataset, slide.dataset);
if(slide.dataset.src){
// Use data-src for on-demand loading
slideEl.dataset.src = slide.dataset.src;
} else {
slideEl.dataset.src = slide.src;
}
if(typeof slide.dataset !== 'undefined'){
_deepExtend(slideEl.dataset, slide.dataset);
if(slide.dataset.src){
// Use data-src for on-demand loading
slideEl.dataset.src = slide.dataset.src;
} else {
slideEl.dataset.src = slide.src;
}

// HiDPI support
if(_isHighDPI() && slide.dataset.src2x){
slideEl.dataset.src = slide.dataset.src2x;
// HiDPI support
if(_isHighDPI() && slide.dataset['src-2x']){
slideEl.dataset.src = slide.dataset['src-2x'];
}
} else {
// IE
if(slide.getAttribute('data-src')){
slideEl.setAttribute('data-src', slide.getAttribute('data-src'));
} else {
slideEl.setAttribute('data-src', slide.getAttribute('src'));
}
}

if(href) slideEl.setAttribute('href', href);
Expand Down Expand Up @@ -316,6 +333,11 @@ var IdealImageSlider = (function() {
_addClass(this._attributes.currentSlide, this.settings.classes.currentSlide);
_addClass(this._attributes.nextSlide, this.settings.classes.nextSlide);

_addClass(this._attributes.container, this.settings.classes.directionPrevious);
setTimeout(function(){
_removeClass(this._attributes.container, this.settings.classes.directionPrevious);
}.bind(this), this.settings.transitionDuration);

if(this.settings.transitionDuration){
_addClass(this._attributes.container, this.settings.classes.animating);
setTimeout(function(){
Expand Down Expand Up @@ -353,6 +375,11 @@ var IdealImageSlider = (function() {
_addClass(this._attributes.currentSlide, this.settings.classes.currentSlide);
_addClass(this._attributes.nextSlide, this.settings.classes.nextSlide);

_addClass(this._attributes.container, this.settings.classes.directionNext);
setTimeout(function(){
_removeClass(this._attributes.container, this.settings.classes.directionNext);
}.bind(this), this.settings.transitionDuration);

if(this.settings.transitionDuration){
_addClass(this._attributes.container, this.settings.classes.animating);
setTimeout(function(){
Expand Down

0 comments on commit 182140b

Please sign in to comment.