- Posts: 11
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ var ticksArray = [ [1, '-7'], [2, '-6'], [3, '-5'], [4, '-4'], [5, '-3'], [6, '-2'], [7, '-1'], [8, '0'], [9, '1'], [10, '2'], [11, '3'], [12, '4'], [13, '5'], [14, '6'], [15, '7'], ]; var ticksArray2 = [ [1, '<img src="/lime3/upload/surveys/769143/images/smiley_red_401.png">'], [2, ''], [3, ''], [4, ''], [5, ''], [6, ''], [7, ''], [8, '<img src="/lime3/upload/surveys/769143/images/smiley_yellow_401.png">'], [9, ''], [10, ''], [11, ''], [12, ''], [13, ''], [14, ''], [15, '<img src="/lime3/upload/surveys/769143/images/smiley_green_401.png">'], ]; insertSliderTicks('{QID}', ticksArray); insertSliderTicks2('{QID}', ticksArray2); }); /* Insert Slider Tick Marks */ function insertSliderTicks(qID, ticksArray) { var thisQuestion = $('#question'+qID); $(thisQuestion).addClass('with-inserted-ticks'); $('input:text', thisQuestion).on('slideEnabled',function(){ var thisSlider = $(this); var thisItem = $(thisSlider).closest('li'); var thisMin = $('.slider-handle:eq(0)', thisItem).attr('aria-valuemin'); var thisMax = $('.slider-handle:eq(0)', thisItem).attr('aria-valuemax'); var thisRange = thisMax - thisMin; $.each(ticksArray, function(i, val) { var tickRelativePosition = val[0] - thisMin; var tickPercent = (tickRelativePosition/thisRange)*100; // Insert tick marks $('.slider-handle:eq(0)', thisItem).before('<div class="inserted-tick left-'+tickPercent+'" style="left: '+tickPercent+'%">\ <div class="tick-text">'+val[1]+'</div>\ </div>'); }); }); } /* Insert Slider Tick Marks */ function insertSliderTicks2(qID, ticksArray2) { var thisQuestion = $('#question'+qID); $(thisQuestion).addClass('with-inserted-ticks'); $('input:text', thisQuestion).on('slideEnabled',function(){ var thisSlider = $(this); var thisItem = $(thisSlider).closest('li'); var thisMin = $('.slider-handle:eq(0)', thisItem).attr('aria-valuemin'); var thisMax = $('.slider-handle:eq(0)', thisItem).attr('aria-valuemax'); var thisRange = thisMax - thisMin; $.each(ticksArray2, function(i, val) { var tickRelativePosition = val[0] - thisMin; var tickPercent = (tickRelativePosition/thisRange)*100; // Insert tick marks $('.slider-handle:eq(0)', thisItem).before('<div class="inserted-tick2 left-'+tickPercent+'" style="left: '+tickPercent+'%">\ <div class="tick-text">'+val[1]+'</div>\ </div>'); }); }); } </script>
<style type="text/css">/* Slider Tick Marks */ @media only screen and (min-width: 768px) { .with-inserted-ticks .slider-container { padding-right: 30px; padding-left: 30px; } } .with-inserted-ticks .slider-item { margin-bottom: 50px; } .with-inserted-ticks .slider-container .help-block { margin: 25px 0 0 -20px; width: 40px; text-align: center; } .with-inserted-ticks .slider-container .help-block.pull-right { margin: 25px -20px 0 0; } .inserted-tick, .inserted-tick2 { position: absolute; top: 20%; height: 20px; width: 4px; margin-top: -5px; margin-left: -1px; background-color: #DDDDDD; background-color: green; } .inserted-tick2.left-0, .inserted-tick2.left-100, .inserted-tick.left-0, .inserted-tick.left-100 { background-color: transparent; background-color: green; } .inserted-tick2 .tick-text { position: absolute; top: -250%; width: 100px; margin-left: -50px; color: #000000; text-align: center; } .inserted-tick .tick-text { position: absolute; top: 150%; width: 100px; margin-left: -50px; color: #000000; text-align: center; } @media only screen and (max-width: 768px) { .inserted-tick.left-0 .tick-text { margin-left: 0px; text-align: left; } .inserted-tick.left-100 .tick-text { margin-left: -100px; text-align: right; } } </style>
var ticksArray = [ [1, '9'], [2, '8'], [3, '7'], [4, '6'], ... [8, '2'], [9, '1'], [10, '2'], [11, '3'], ... [16, '8'], [17, '9']
var ticksArray = [ [-8, '9'], [-7, '8'], [-6, '7'], [-5, '6'], ... [-1, '2'], [0, '1'], [1, '2'], [2, '3'], ... [7, '8'], [8, '9']
.slider .tooltip {display:none; }
@media only screen and (min-width: 768px) { .slider-list .slider-left, .slider-list .slider-right { margin-top: 0em; } }