가능한 경우 누구에게 알리거나 html data
속성을 사용하여 모바일 또는 데스크톱에 따라 다른 콘텐츠를로드하는 방법은 무엇입니까? gif 요소에 data-gif
태그를 설정하고 video 요소에 data-video
태그를 설정했습니다.데이터 html 속성을 사용하여 다른 콘텐츠로드
화면 크기에 따라 다른 콘텐츠를로드하는 것이 가능하지만이를 구현할 수 없다는 것을 알고 있습니다. 화면 크기에 따라 요소를 숨기고 싶지는 않지만 요소를 전혀로드하지 않으려합니다.
아래 코드를 참조하십시오. 나는 위에서 설명한 바를 여러 가지 방법으로 시도했지만 성공하지 못했습니다.
<div id="main>
<div class="box-one>
<img data-gif='http://static1.squarespace.com/static/552a5cc4e4b059a56a050501/565f6b57e4b0d9b44ab87107/566024f5e4b0354e5b79dd24/1449141991793/NYCGifathon12.gif'>
<video data-video width="640" height="360" controls="" autoplay=""><source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4"><source src="http://clips.vorwaerts-gmbh.de/VfE.webm" type="video/webm"><source src="http://clips.vorwaerts-gmbh.de/VfE.ogv" type="video/ogg"></video>';
</div>
<div class="box-two>
<img data-gif='http://static1.squarespace.com/static/552a5cc4e4b059a56a050501/565f6b57e4b0d9b44ab87107/566024f5e4b0354e5b79dd24/1449141991793/NYCGifathon12.gif'>
<video data-video width="640" height="360" controls="" autoplay=""><source src="http://clips.vorwaerts-gmbh.de/VfE_html5.mp4" type="video/mp4"><source src="http://clips.vorwaerts-gmbh.de/VfE.webm" type="video/webm"><source src="http://clips.vorwaerts-gmbh.de/VfE.ogv" type="video/ogg"></video>';
</div>
</div>
JAVASCRIPT
(function(){
var windowWidth = $(window).width();
var maxDeviceWidth = 768;
if (windowWidth > maxDeviceWidth) {
//show video
} else {
//show gif
}
})();
여기 왜 데이터 attr을 사용 하시겠습니까? 숨기기/표시 사용 – Ish
나는 서버에서 내용을로드하고 화면 크기에 따라 다른 내용을로드하지 않으려 고합니다. –