class CardElement extends HTMLElement {
constructor() {
super();
let shadow = this.attachShadow({mode: open});
let div = document.createElement('div');
let div_main = div;
div_main.className = "demo-card-square mdl-card mdl-shadow--2dp";
shadow.appendChild(div_main);
let div_sec = div;
div_sec.className = "mdl-card__title mdl-card--expand";
div_sec.style.background = this.getAttribute('src');
shadow.appendChild(div_sec);
let h2 = document.createElement('h2');
h2.className = "mdl-card__title-text";
h2.innerHTML = this.getAttribute('text');
shadow.appendChild(h2);
let div_three = div;
div_three.className = "mdl-card__supporting-text";
div_three.innerHTML = this.getAttribute('support-text');
shadow.appendChild(div_three);
let div_border = div;
div_border.className ="mdl-card__actions mdl-card--border";
shadow.appendChild(div_border);
let anchor = document.createElement('a');
anchor.className = "mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect";
shadow.appendChild(anchor);
}
}
customElements.define('card-element', CardElement);
}
위의 코드와 같이 사용자 정의 요소에 카드 구성 요소 (https://getmdl.io/components/index.html#cards-section)를 만들려고했습니다. 그러나 적절한 출력을 볼 수 없었습니다. 웹용 응용 프로그램을 개발하기 시작한 이후 도움이되었습니다.이 맞춤 요소가 작동합니까? 나는 그것을 벗었다 Material Design lite
<card-element src="img.jpg" text="Inside" support-text="Can you see what I've done here!"></card-element>
그리고 이것은 나에게 오류 보여주고있다 : 나는이 문제를 다루는되어야하는 방법 Uncaught TypeError: Failed to execute 'attachShadow' on 'Element': The provided value 'function open() { [native code] }' is not a valid enum value of type ShadowRootMode. at new CardElement
그래서 당신이 나를 왜하지 작업 또는를 할 수 있습니다.
좋아, 도움이 있지만, 구성 요소의 몇의 H2의 div_border 앵커가 #shadowRoot –
찾는 볼 수 있습니다 그 이 답변에 : https://stackoverflow.com/a/45922695/4600982 – Supersharp