我已经编辑了 Bootstrap Slider 的属性,如下所示:
<!DOCTYPE html>
<html>
<head>
<title>Slider</title>
<script LANGUAGE="JavaScript" src="jquery.min.js" type="text/javascript"></script>
<script LANGUAGE="JavaScript" src="bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
html,
body,
#Myslider {
position: absolute;
left: 500px;
}
#Myslider.slider-selection,
#Myslider.slider-track-low {
background-color: black;
}
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="bootstrap-slider.css">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
<p align="center" id="demo">Start Sliding !</p>
<input id="Myslider" data-provide="slider" data-slider-min="1" data-slider-max="12" data-slider-step="1" data-slider-value="1" data-slider-selection="after" />
<script>
function main() {
$('#Myslider').slider();
$("#Myslider").on("slide", function(slideEvt) {
$("#SliderVal").text(slideEvt.value);
if ($('#Myslider').val() == 1) {
document.getElementById("demo").innerHTML = "Genel endeks";
}
if ($('#Myslider').val() == 2) {
document.getElementById("demo").innerHTML = "Konut";
}
if ($('#Myslider').val() == 3) {
document.getElementById("demo").innerHTML = "Çalışma hayatı";
}
if ($('#Myslider').val() == 4) {
document.getElementById("demo").innerHTML = "Gelir ve servet";
}
if ($('#Myslider').val() == 5) {
document.getElementById("demo").innerHTML = "Sağlık";
}
if ($('#Myslider').val() == 6) {
document.getElementById("demo").innerHTML = "Eğitim";
}
if ($('#Myslider').val() == 7) {
document.getElementById("demo").innerHTML = "Çevre";
}
if ($('#Myslider').val() == 8) {
document.getElementById("demo").innerHTML = "Güvenlik";
}
if ($('#Myslider').val() == 9) {
document.getElementById("demo").innerHTML = "Sivil katılım";
}
if ($('#Myslider').val() == 10) {
document.getElementById("demo").innerHTML = "Altyapı hizmetlerine erişim";
}
if ($('#Myslider').val() == 11) {
document.getElementById("demo").innerHTML = "Sosyal yaşam";
}
if ($('#Myslider').val() == 12) {
document.getElementById("demo").innerHTML = "Yaşam memnuniyeti";
}
});
}
window.onload = main;
</script>
</body>
</html>
您还可以在JSFiddle上查看此代码。
然后我在 carto 上创建了一个地图,并尝试在这个 HTML 页面上添加这个滑块;
<!DOCTYPE html>
<html>
<head>
<title>Living Index</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="author" content="capanh">
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" />
<script LANGUAGE="JavaScript" src="jquery.min.js" type="text/javascript"></script>
<script LANGUAGE="JavaScript" src="bootstrap-slider.js" type="text/javascript"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
html,
body,
#map {
height: 600px;
width: 1900px;
left: 0px;
padding: 0;
margin: 0;
}
#Myslider {
position: absolute;
left: 850px;
}
#Myslider.slider-selection,
#Myslider.slider-track-low {
background-color: black;
}
</style>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" />
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.ie.css" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="bootstrap-slider.css">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
</head>
<body>
<div id="map"></div>
<div id="legend"></div>
<p align="center" id="demo">Kaydirmaya Basla !</p>
<input id="Myslider" data-provide="slider" data-slider-min="1" data-slider-max="12" data-slider-step="1" data-slider-value="1" data-slider-selection="after" />
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
function main() {
var map = new L.Map('map', {
zoomControl: false,
center: [38.9765, 35.3320],
zoom: 5
});
L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg', {
attribution: 'CartoDB · OSM data'}).addTo(map);
cartodb.createLayer(map, 'https://capanh.carto.com/api/v2/viz/94dd9018-e918-11e6-a6cf-0ef7f98ade21/viz.json', {
legends: true
}).addTo(map);
$('#Myslider').slider();
$("#Myslider").on("slide", function(slideEvt) {
$("#SliderVal").text(slideEvt.value);
if ($('#Myslider').val() == 1) {
document.getElementById("demo").innerHTML = "Genel endeks";
}
if ($('#Myslider').val() == 2) {
document.getElementById("demo").innerHTML = "Konut";
}
if ($('#Myslider').val() == 3) {
document.getElementById("demo").innerHTML = "Çalışma hayatı";
}
if ($('#Myslider').val() == 4) {
document.getElementById("demo").innerHTML = "Gelir ve servet";
}
if ($('#Myslider').val() == 5) {
document.getElementById("demo").innerHTML = "Sağlık";
}
if ($('#Myslider').val() == 6) {
document.getElementById("demo").innerHTML = "Eğitim";
}
if ($('#Myslider').val() == 7) {
document.getElementById("demo").innerHTML = "Çevre";
}
if ($('#Myslider').val() == 8) {
document.getElementById("demo").innerHTML = "Güvenlik";
}
if ($('#Myslider').val() == 9) {
document.getElementById("demo").innerHTML = "Sivil katılım";
}
if ($('#Myslider').val() == 10) {
document.getElementById("demo").innerHTML = "Altyapı hizmetlerine erişim";
}
if ($('#Myslider').val() == 11) {
document.getElementById("demo").innerHTML = "Sosyal yaşam";
}
if ($('#Myslider').val() == 12) {
document.getElementById("demo").innerHTML = "Yaşam memnuniyeti";
}
});
}
window.onload = main;
</script>
</body>
</html>
最终结果是一个文本框而不是一个滑块。首先,我认为这是一个参考错误。但是,正如您在第一个代码块中看到的那样,滑块单独使用时使用相同的引用。为什么我在文件中添加地图时它不起作用?有没有人见过这样的事情?