Solved

HTML5 Data attributes and Responsive Design

Posted on 2013-06-18
8
256 Views
Last Modified: 2013-06-24
I am using html5 data attributes to help implement some animation of certain page elements. They adjust positioning based on the scroll position of the page. The positions are % based However on smaller screens i need to adjust the values of the percentages. Since they are outside the css i cant use media queries, is there any way to call different data attributes for specified elements based on screen size?
0
Comment
Question by:orbitdsgn
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:rgranlund
Comment Utility
Why can't you use a media query in your CSS?

@media screen and (min-width:300px; , max-width:320px;) {...css classes and id's...}
0
 

Author Comment

by:orbitdsgn
Comment Utility
I cant use media queries because the data attributes are defined in the html not the css

see example below:
<div id="intro1" data-0="left:20%; top:180px;" data-800="left:20%; top:0px;">
        
    </div>

Open in new window


is it possible to include the data attributes in the css instead?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
ALL properties/values used for presentation belong in the CSS.  I assume you are using some kind of third rate theme or template that generates a lot of junk using values embedded in the HTML.  Lot's of luck with that!

If you post a link to the page then we can probably make recommendations on how to make it responsive using standard methods without having to jump through hoops, and getting knotted up with hacks.

Cd&
0
 

Author Comment

by:orbitdsgn
Comment Utility
Cd&

I dont think you read the question. You will see that the data attributes in the html are used to trigger an animation when the user reaches a certain scroll point in the example above the first data attribute is the position of the intro1 div when the page has not been scrolled the second data-800 is when the user has scrolled 800 pixels. Unless you know of a way to incorporate the scroll position into the css I'm thinking it needs to stay in the html. This is not a theme or template and has been coded from scratch

You can see the site here
http://www.thedancingrobot.com/crest/redo2/custom.html
Clearly a work in progress thats why I am looking for some help here
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 53

Expert Comment

by:COBOLdinosaur
Comment Utility
First of all, if you are going to use data attributes you should be using an HTML5 doctype or you are going to run into cross-browser issues.

Now that you posted a link I see whay youare doing, and I  think all you need to do is use vh and vw instead of percentages.  One vh is equal to 1/100 of the height of the viewport. 1 vw is equal to 1/100 of the width of the viewport.

The adjust automatically to resolution, and screen size changes, and most of the time will handle an orientation change on supporting devices.

You can check here to see how to use vh and vw


Cd&
0
 

Author Comment

by:orbitdsgn
Comment Utility
Thanks COBOLdinosaur,

Good call on the doctype, and the vh, vw is cool but unfortunately i don't think ill get the cross browser support i need.
0
 

Accepted Solution

by:
orbitdsgn earned 0 total points
Comment Utility
its certainly not best practice but heres what im going to do. I am going to create at least two versions of the site one for large screens lets say wider than 1200px and on for small screens down to 800px wide, mobile will be handled with a diffrent site specifically for use on mobile devices. I will then call the specific site for the screen size using

<SCRIPT language="JavaScript">
<!--
if ((screen.width>=1200) && (screen.height>=768))
{
 window.location="highres.html";
}
else
{
  window.location="lowres.html";
}
//-->
</SCRIPT>

Open in new window

0
 

Author Closing Comment

by:orbitdsgn
Comment Utility
Certainly not idea but since cross browser compatability is important this seems to be a decient work around
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now