Skip to content

Instantly share code, notes, and snippets.

@llakewood
Last active January 12, 2016 18:55
Show Gist options
  • Save llakewood/a7ad967d4c88473a0972 to your computer and use it in GitHub Desktop.
Save llakewood/a7ad967d4c88473a0972 to your computer and use it in GitHub Desktop.
Questionnaire Prototype
<div id="target-examples" class="section part row">
<div class="small-12 columns">
<h1>Questionnaire Prototype</h1>
<h2>with jQuery scrollTo</h2>
<ul class="links">
<li><a title="$(...).scrollTo('s_1', 365);" class="link" data-step="[0,2]" href="#">0</a></li>
<li><a title="$(...).scrollTo('s_1', 365);" class="link" data-step="[1,0]" href="#">1</a></li>
<li><a title="$(...).scrollTo('s_2', 365);" class="link" data-step="[2,0]" href="#">2</a></li>
</ul>
</div>
<div class="small-12 columns">
<div id="pane-target" class="pane">
<ul class="elements row" style="height:1011px; width:100000000px;">
<li id="s_0_q_0" class="small-12 left"><p>0</p>
<ul>
<li id="s_0_q_1">
<h2>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</h2>
<a href="#" class="link" data-step="[0,2]">Yes [0,2]</a>
<a href="#" class="link" data-step="[1,0]">No [1,0]</a>
</li>
<li id="s_0_q_2">
<h2>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</h2>
<a href="#" class="link" data-step="[1,2]">Yes [1,2]</a>
<a href="#" class="link" data-step="[2,0]">No [2,0]</a>
</li>
</ul>
</li>
<li id="s_1_q_0" class="small-12 left"><p>1</p>
<ul>
<li id="s_1_q_1">
<h2>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</h2>
<a href="#" class="link" data-step="[1,2]">Yes [1,2]</a>
<a href="#" class="link" data-step="[2,0]">No [2,0]</a>
</li>
<li id="s_1_q_2">
<h2>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</h2>
<a href="#" class="link" data-step="[2,0]">Yes [0,2]</a>
<a href="#" class="link" data-step="[1,1]">No [1,1]</a>
</li>
</ul>
</li>
<li id="s_2_q_0" class="small-12 left"><p>2</p>
<ul>
<li id="s_2_q_1">
<h2>Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato. Dandelion cucumber earthnut pea peanut soko zucchini.</h2>
<a href="#" class="link" data-step="[1,1]">Yes [1,2]</a>
<a href="#" class="link" data-step="[2,0]">No [2,0]</a>
</li>
<li id="s_2_q_2">
<h2>Turnip greens yarrow ricebean rutabaga endive cauliflower sea lettuce kohlrabi amaranth water spinach avocado daikon napa cabbage asparagus winter purslane kale. Celery potato scallion desert raisin horseradish spinach carrot soko. Lotus root water spinach fennel kombu maize bamboo shoot green bean swiss chard seakale pumpkin onion chickpea gram corn pea. Brussels sprout coriander water chestnut gourd swiss chard wakame kohlrabi beetroot carrot watercress. Corn amaranth salsify bunya nuts nori azuki bean chickweed potato bell pepper artichoke.</h2>
<a href="#" class="link" data-step="[0,2]">Yes [0,2]</a>
<a href="#" class="link" data-step="[1,1]">No [1,1]</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>

Questionnaire Prototype

A questionnaire prototype, using jQuery scrollTo template for working with many elements on the page.

A Pen by VarCo on CodePen.

License.

jQuery(function( $ ){
/**
* Demo binding and preparation, no need to read this part
*/
//borrowed from jQuery easing plugin
//http://gsgd.co.uk/sandbox/jquery.easing.php
$.easing.elasout = function(x, t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
};
$('a.back').click(function() {
$(this).parents('div.pane').scrollTo(0, 800, { queue:true });
$(this).parents('div.section').find('span.message').text( this.title);
return false;
});
//just for the example, to stop the click on the links.
$('ul.links').click(function(e){
var link = e.target;
if (link.target === '_blank') {
return;
}
e.preventDefault();
link.blur();
if (link.title) {
$(this).parent().find('span.message').text(link.title);
}
});
// This one is important, many browsers don't reset scroll on refreshes
// Reset all scrollable panes to (0,0)
$('div.pane').scrollTo(0);
// Reset the screen to (0,0)
$.scrollTo(0);
// TOC, shows how to scroll the whole window
$('#toc a').click(function() {//$.scrollTo works EXACTLY the same way, but scrolls the whole screen
$.scrollTo(this.hash, 1500, { easing:'elasout' });
$(this.hash).find('span.message').text(this.title);
return false;
});
// Target examples bindings
var $target = $('#pane-target');
$('#target-examples a').click(function() {
$target.stop(true);
});
$('.link').click(function() {
var data = [],
location = this.dataset.step,
step,
question,
goTo,
offset = 0,
queue = false;
location = location.split(',');
step = location[0].substr(1);
question = location[1].substr(-2,1);
goTo = '#s_' + step + '_q_' + question;
console.log(goTo);
if(parseInt(question, 10) > 0) {
offset = -40;
}
$target.scrollTo(goTo, 365, {
offset: offset
});
$('.pane ul li').addClass('prepForAnimation').delay( 300 ).removeClass('prepForAnimation');
});
});
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js"></script>
* {
-webkit-transition: all 1s
}
ul,li,h1,h2,h3,h4,p{
list-style:none;
padding:0;
margin:0;
}
.part h3,
.part h4,
.part h4 a {
color:#933;
}
.section{
width:950px;
padding:10px;
margin: 5px auto;
position:relative;
clear:both;
}
.section * {
text-align:left;
}
.section li{
float:left;
}
.pane{
overflow:auto;
clear:left;
margin: 10px 0 0 10px;
position:relative;
width:826px;
height:500px;
}
ul.elements li{
width:800px;
font-weight:bolder;
text-align:center;
padding:50px;
position:relative;
clear: both;
}
ul.elements li ul li{
height:initial;
width: 500px;
clear: both;
}
ul.elements li a {
color:#933;
font-size:12px;
}
ul.elements li p{
color:#666;
}
#pane-settings ul.elements li{
margin:5px;
}
#pane-settings{
margin-bottom:10px;
}
ul.links{
height:20px;
overflow:hidden;
padding-left: 5px;
}
ul.links a{
color:#69C;
margin:0 0 0 5px;
}
.clear{
clear:left;
}
h1{
color:#5B739C;
}
h1 strong{
font-size:13px;
color:#777;
}
.prepForAnimation {
animation-duration: 3s;
animation-name: slidein;
}
@keyframes slidein {
from {
opacity: 1;
}
to {
opacity: 0;
}
to {
opacity: 1;
}
}
<link href="http://demos.flesler.com/base.css" rel="stylesheet" />
<link href="http://pp.gocactus.com/css/app.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment