Skip to content

Instantly share code, notes, and snippets.

@sheriffderek
Last active January 31, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheriffderek/3bba20d069e6ddb98556dff9265f7f90 to your computer and use it in GitHub Desktop.
Save sheriffderek/3bba20d069e6ddb98556dff9265f7f90 to your computer and use it in GitHub Desktop.
mouseEnter / mouseLeave example
import Ember from 'ember';
import { htmlSafe } from '@ember/string';
export default Ember.Component.extend({
classNames: ['background-trigger'],
classNameBindings: [
'active:hovered', // when 'active' is true - bind the CSS class 'hovered' to this component
],
thing: null,
active: false,
mouseEnter() {
this.set('active', true);
},
mouseLeave() {
this.set('active', false);
},
backgroundStyle: Ember.computed('thing', function() {
const image = this.get('thing.image');
return htmlSafe(`background-image: url('${image}');`);
}),
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['welcome-area'],
items: [
{
name: "one",
image: "https://placehold.it/1600/0066ff",
},
{
name: "two",
image: "https://placehold.it/1600/ff0066",
},
{
name: "three",
image: "https://placehold.it/1600/6600ff",
},
],
// set background image...
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'sub-component changes parent class?',
});
* {box-sizing: border-box};
html, body {
height: 100%;
}
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
background: lightgray;
}
.welcome-area {
/* */
}
.background-fill {
width: 20px;
height: 20px;
border: 1px solid red;
background-size: cover;
background-position: center;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
pointer-events: none;
opacity: 0;
transition: opacity 1s;
}
.background-trigger {
cursor: pointer;
}
.background-trigger.hovered .background-fill{
z-index: -1;
opacity: 1;
}
<h1>{{appName}}</h1>
<WelcomeArea />
<div class='background-fill'
style={{backgroundStyle}}
>
</div>
<h3>Background trigger {{thing.name}}</h3>
<h2>Welcome area</h2>
{{#each items as |item|}}
<BackgroundTrigger @thing={{item}} />
{{/each}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment