大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
想要移动效果需要结合定时器来做吧。
专注于为中小企业提供网站制作、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业昌平免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000多家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
setInterval来实现。或者用jq的animate方法。
window.onmousewheel = function(){ //触发滚轮事件
}
window.onscroll = function(){ //滚动条事件
}
//其实你的问题直接使用判断滚动条应该就可以了,但是如果一定要拖动滚动条才执行事件,我们可以通过获取鼠标位置来模拟
var a = document.getElementsByTagName("html")[0];
window.onmousemove = function(){
//一般默认滚动条12px宽,当鼠标位于浏览器窗口右边12px内按下鼠标可以视为拖动滚动条
if(innerWidth - event.clientX 12){
a.onmousedown = function(){
console.log(1);
}
}else{
a.onmousedown = null;
}
}
!DOCTYPE html
html
head lang="en"
meta charset="UTF-8"
meta name="viewport" content="width=device-width, initial-scale=1.0"
title/title
link href="css/bootstrap.min.css" rel="stylesheet"
link href="css/plugins/nouslider/nouislider.min.css" rel="stylesheet"
/head
body
div class="col-lg-6"
div class="ibox float-e-margins col-lg-12" style="clear: both;"
div class="ibox-title"
h5Bar Chart Example/h5
/div
div class="ibox-content" style="clear: both;"
div
canvas id="barChart" height="140" style="height: 300px;"/canvas
/div
/div
/div
div class="col-lg-12"
div id="drag-fixed" class="slider_red"/div
/div
/div
script src="js/jquery-2.1.1.js"/script
script src="js/bootstrap.min.js"/script
!-- NouSlider --
script src="js/plugins/nouslider/nouislider.min.js"/script
script src="js/plugins/chartJs/Chart.min.js"/script
script
//dataObj后台动态生成
var DataObj=[{"labels":["2014-5-6","2014-5-7","2014-5-8","2014-5-9","2014-5-10","2014-5-11","2014-5-12"],"data1":[30,29,45,60,100,200,154],"data2":[100,125,325,214,124,124,124]},
{"labels":["2015-6-6","2015-6-7","2015-6-8","2015-6-9","2015-6-10","2015-5-11","2015-6-12"],"data1":[40,29,45,100,120,250,354],"data2":[300,145,325,284,174,20,50]},
{"labels":["2016-6-6","2016-6-7","2016-6-8","2016-6-9","2016-6-10","2016-5-11","2016-6-12"],"data1":[40,29,45,100,120,250,354],"data2":[300,145,325,284,174,20,50]},
{"labels":["2017-6-6","2017-6-7","2017-6-8","2017-6-9","2017-6-10","2017-5-11","2017-6-12"],"data1":[320,29,45,100,120,250,354],"data2":[390,165,325,284,174,240,50]},
{"labels":["2014-5-6","2014-5-7","2014-5-8","2014-5-9","2014-5-10","2014-5-11","2014-5-12"],"data1":[30,29,45,60,100,200,154],"data2":[100,125,325,214,124,124,124]}];
// star绘制柱状图
var barData = {
labels: [],
datasets: [
{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: []
},
{
label: "My Second dataset",
fillColor: "rgba(26,179,148,0.5)",
strokeColor: "rgba(26,179,148,0.8)",
highlightFill: "rgba(26,179,148,0.75)",
highlightStroke: "rgba(26,179,148,1)",
data: []
}
]
};
var barOptions = {
scaleBeginAtZero: true,
scaleShowGridLines: true,
scaleGridLineColor: "rgba(0,0,0,.05)",
scaleGridLineWidth: 1,
barShowStroke: true,
barStrokeWidth: 2,
barValueSpacing: 5,
barDatasetSpacing: 1,
responsive: true
};
var ctx = document.getElementById("barChart").getContext("2d");
// 柱形图初始值
$(function(){
barData.labels=DataObj[3].labels;
barData.datasets[0].data=DataObj[3].data1;
barData.datasets[1].data=DataObj[3].data2;
var myNewChart = new Chart(ctx).Bar(barData,barOptions);//加载更新图表
});
var Slider = document.getElementById('drag-fixed');
//end 结束绘制
// 开始滑动条
noUiSlider.create(Slider, {
start: 4,//滑动条开始出现的位置
connect: [true,false],
range: {
'min':0,//滑动条长度最小值
'max': 4 //滑动条长度最大值
},
step:1//步数
});
Slider.noUiSlider.on('slide', function ( values, handle ) {
// $("#test-data").text(values[handle]);//得到滑条的值
// $("#test-data").text(this.get()); this.get() 得到滑条的值
var index=parseInt(this.get());
barData.labels=DataObj[index].labels;
barData.datasets[0].data=DataObj[index].data1;
barData.datasets[1].data=DataObj[index].data2;
var myNewChart = new Chart(ctx).Bar(barData, barOptions);
});
// 结束滑动条
/script
/body
/html
很多时候,需要对div进行固定,比如在线咨询模块,这就需要固定div在显示页面的位置,而不能随滚动条滚动。
思路:将需要固定的div做成悬浮框,目的是能和别的div块重合,然后当触发滚动条事件,动态改变div坐标。
代码:
jsp中:
body
div style="position: absolute;z-index:90" id="div1"我不动/div
div我动div
/body
//有的将position设置成fixed,我试了试效果不如position好,设置z-index,向里的深度,我这儿设置90,你要覆盖几个div,设置数大于那个数就行。
js中:
我这儿用jquery写。
$(document).ready(function(){
$(window).scroll(function(){//滚动时触发函数
$("#div1").css("top",$(document).scrollTop());//将滚动条高度赋给悬浮框。
})
})
导入jquery库,效果就出来了。
这个是个在网页上玩的flash游戏吧?
将该网站添加到受信任的站点就可以