diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-10-08 17:37:56 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-10-08 17:37:56 -0400 |
| commit | 18e90995c4a0f17aba37d9e8a6b2e36002b7a491 (patch) | |
| tree | d2ea73a2ff7a8eff47c86f0a82ee7d012c418ec8 | |
| parent | 5b12dd422167c5aaf210d49d57b78312eb209b94 (diff) | |
rotating through images on hover
| -rw-r--r-- | public/assets/javascripts/ui/site/ProjectList.js | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/public/assets/javascripts/ui/site/ProjectList.js b/public/assets/javascripts/ui/site/ProjectList.js index 149cd41..ebb0a96 100644 --- a/public/assets/javascripts/ui/site/ProjectList.js +++ b/public/assets/javascripts/ui/site/ProjectList.js @@ -1,4 +1,4 @@ - +var projectListTimeout = null var ProjectList = View.extend({ el: ".projectList", @@ -9,20 +9,38 @@ var ProjectList = View.extend({ }, initialize: function(){ + this.$(".images").each(function(){ + $divs = $(this).children("div") + $divs.hide() + $divs.first().show() + $(this).data("index", 0) + }) }, timeout: null, - enter: function(){ - clearTimeout(this.timeout) - this.advance() + enter: function(e){ + clearTimeout(projectListTimeout) + this.advance(e.currentTarget) }, - leave: function(){ - clearTimeout(this.timeout) + leave: function(e){ + clearTimeout(projectListTimeout) + var $divs = $(e.currentTarget).find(".images div") + $divs.hide() + $divs.eq(0).show() }, - advance: function(){ - this.timeout = setTimeout(this.advance.bind(this), 500) + advance: function(el){ + projectListTimeout = setTimeout(function(){ + this.advance(el) + }.bind(this), 500) + var $images = $(el).find(".images") + var $divs = $images.children("div") + var index = $images.data("index") + var nextIndex = (index + 1) % $divs.length + $divs.eq(index).hide() + $divs.eq(nextIndex).show() + $images.data("index", nextIndex) } /* |
