Skip to content

Instantly share code, notes, and snippets.

@sido
Created June 19, 2011 15:23
Show Gist options
  • Save sido/1034406 to your computer and use it in GitHub Desktop.
Save sido/1034406 to your computer and use it in GitHub Desktop.
Flashcard UI: Part 2
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ui.Flashcard</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/pepper-grinder/jquery-ui.css">
<link rel="stylesheet" href="ui.flashcard.css">
<style>
body { font-family: sans-serif; }
#myFlashcard { margin: 2em auto; }
</style>
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.4/modernizr.min.js"></script>
</head>
<body>
<dl id="myFlashcard">
<dt>Who ya gonna call?</dt>
<dd>GHOSTBUSTERS!</dd>
</dl>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
<script src="ui.flashcard.js"></script>
<script>
$("#myFlashcard").flashcard({ time: 10 });
</script>
</body>
</html>
.ui-flashcard {
font-size: 1.6em;
height: 150px;
position: relative;
width: 350px;
}
.ui-flashcard dt,
.ui-flashcard dd {
height: 100%;
left: 0;
line-height: 150px; /* vertical align text */
margin: 0;
padding: 0;
position: absolute;
text-align: center;
top: 0;
width: 100%;
}
.ui-flashcard dt {
cursor: pointer;
font-style: italic;
}
.ui-flashcard dd {
z-index: -1;
}
(function($, undefined) {
$.widget("ui.flashcard", {
options: {
time: 5
},
_create: function() {
var widget = this;
this.element
.addClass("ui-flashcard ui-widget")
.find("dt, dd")
.addClass("ui-widget-content ui-corner-all")
.end()
.bind("show", function() {
widget.show();
})
.find("dt")
.click(function() {
widget.element.trigger("show");
})
;
var t = setTimeout(function() {
widget.show();
}, this.options.time * 1000);
},
show: function() {
this.element.find("dt").fadeOut("slow");
},
_destroy: function() {
this.element
.removeClass("ui-flashcard ui-widget ui-corner-all")
.find("dt, dd")
.addClass("ui-widget-content")
;
}
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment