Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprite for :hover states? #65

Open
sahibalejandro opened this issue Apr 8, 2015 · 9 comments
Open

Sprite for :hover states? #65

sahibalejandro opened this issue Apr 8, 2015 · 9 comments

Comments

@sahibalejandro
Copy link

Is there an option or something to generate :hover states for the sprites?

for example, having button.png and button-hover.png generates css:

.icon { ... }
.icon-button {
  background-position: ...
  ...
}
.icon-button:hover {
  background-position: ...
}

Compass sprite generator has this feature :(

@alexkaraman85
Copy link

You can use a template to setup your own output.

@sahibalejandro
Copy link
Author

Mustache is "logic-less", this can't be done only using basic template tags, it needs an if with some RegExp validation to detect the -hover suffix on the image name and then generate the :hover styles.

Any ideas?

@aslansky
Copy link
Owner

Hopefully you can wait a few more days. In css-sprite 1.0 handlebars is used to generate the style. This will give much more flexibility. So creating a hover style can be achieved more easily. I just need a few more days to finish up all the changes.

@sahibalejandro
Copy link
Author

Thank you, I'm tuned.

@ghostcode
Copy link

i need this。

gulp.spritesmith do like this:

sprites: {
  src: srcAssets + '/images/sprites/icon/*.png',
  dest: {
    css: srcAssets + '/scss/base/',
    image: srcAssets + '/images/sprites/'
  },
  options: {
    cssName: '_sprites.scss',
    cssFormat: 'css',
    cssOpts: {
      cssClass: function (item) {
        // If this is a hover sprite, name it as a hover one (e.g. 'home-hover' -> 'home:hover')
        if (item.name.indexOf('-hover') !== -1) {
          return '.icon-' + item.name.replace('-hover', ':hover');
          // Otherwise, use the name as the selector (e.g. 'home' -> 'home')
        } else {
          return '.icon-' + item.name;
        }
      }
    },
    imgName: 'icon-sprite.png',
    imgPath: '/assets/images/sprites/icon-sprite.png'
  }
}

@aslansky
Copy link
Owner

css-sprite 1.0.0 is out ... it's called sprity. it now uses handlebars as the template language. So more logic is possible whithin the templates. If this is not enough, have a look at How to write a sprity style processor. Let me know if you need more information ...

@sahibalejandro
Copy link
Author

Thanks, I will check it.
On May 13, 2015 6:40 AM, "Alexander Slansky" [email protected]
wrote:

css-sprite 1.0.0 is out ... it's called sprity
https://github.com/sprity/sprity. it now uses handlebars as the
template language. So more logic is possible whithin the templates. If this
is not enough, have a look at How to write a sprity style processor
https://github.com/sprity/sprity/wiki/How-to-write-a-sprity-style-processor.
Let me know if you need more information ...


Reply to this email directly or view it on GitHub
#65 (comment).

@trisys3
Copy link

trisys3 commented Jan 22, 2016

Did you ever succeed in doing this?

@sahibalejandro
Copy link
Author

Using sprite smith, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants