2017-05-08 47 views
0

我想,爲了改變一些數據百分之當你點擊地圖的區域創造JS的程序。基本上我使用jqvmap作爲Map和一個進度條來顯示用戶點擊的每個區域的一些信息。 什麼我的工作:更改數據%的JS

HTML

<h1>Edificable surface</h1> 
     <div class="skillbar clearfix" data-percent="0%"> 
     <div class="skillbar-title" style="background: #27ae60;"><span>Job</span></div> 
     <div class="skillbar-bar" style="background: #2ecc71;"></div> 
     <div class="skill-bar-percent">100%</div> 
     </div> <!-- End Skill Bar --> 

的JavaScript

jQuery(document).ready(function(){ 
    jQuery('.skillbar').each(function(){ 
    jQuery(this).find('.skillbar-bar').animate({ 
     width:jQuery(this).attr('data-percent') 
    },6000); 
    }); 
}); 

jQuery(document).ready(function() { 
     jQuery('#vmap').vectorMap({ 
      map: 'europe_en', 
      enableZoom: false, 
      showTooltip: true, 
      onRegionClick: function (element, code, region) { 
      if (!touch_detect()) { 
       // we're not on a mobile device, handle the click 
       var message = 'You clicked "' + region + '" which has the code: ' + code.toUpperCase(); 
       document.getElementById('indi').innerHTML = 'You clicked "' + region + '".'; 
      } 
      if (region == 'United Kingdom') { 
      document.getElementByClassName('skillbar clearfix').setAttribute('data-percent', '50%'); 
      } else { 
      document.getElementByClassName('skillbar clearfix').setAttribute('data-percent', '0'); 
      } 
      }, 
      onRegionOver: function (element, code, region) { 
      if (touch_detect()) { 
       /// we're not on a mobile device, handle the click 
       var message = 'You clicked "' + region + '" which has the code: ' + code.toUpperCase(); 
       document.getElementById('indi').innerHTML = 'You clicked "' + region + '".'; 
      } 
     }, 
     }); 
     }); 

第一if語句正常工作,我每次點擊一個區域它顯示我有區點擊,但第二個(如果地區=「英國」)......「不,即使它看起來是正確的。 工作,你有什麼祕訣,我做什麼? 謝謝:)

+0

你可以使你的問題的工作片段?幷包括相關的代碼(HTML,CSS,jQuery的) –

+0

嘗試創建一個小提琴例如鏈接,這樣我們就可以檢查並讓你知道解決 –

+0

[鏈接] https://jsfiddle.net/gkdk29db/ 這是部分代碼...是相當困難的把所有的代碼,因爲那裏是有很多的代碼的地圖。我拿着地圖從這裏 [鏈接] https://github.com/manifestinteractive/jqvmap 我希望它合理! – Sim0

回答

0

HTML:

<div id="chart" class="chart-circle" data-percent="100"></div> 

的JavaScript:

var value = 50; 
$("#chart").attr("data-percent", value.toString());