I am trying to change a data attribute of a div element base on the users screen resolution, i am using the impress.js library and i want to set the div overview that has a data attribute of scale, the value that i want to toggle is 2.0 for desktop and 2.5 for laptop.
So far below is my code.
<div id="overview" class="step" data-x="-700" data-y="-500" data-scale="2">
</div>
My jquery code is.
$(window).resize(function() {
if(window.innerWidth == 1680){
$('#overview').data('scale', 2);
}else{
$('#overview').data('scale', 2.5);
}
})
I am able to get the value of the innerWidth but cannot get to change the value of the data attribute, Any suggestion would be great!
.attr()i.e.$('#overview').attr('data-scale', 2.5);window.innerWidth == 1680need to bewindow.innerWidth <= 1680. because exactly match will not possible all time. And it need to be:-$('#overview').attr('data-scale', 2.5);or$('#overview').attr('data-scale', 2);if($(window).width() >= 1680){}instead your conditiondata-min-scale="1" data-max-scale="1"on your<div id='impress'></div>good try do.