我有以下部分代码用于cordova应用程序:
$('.shadow-slider').addEventListener("touchmove",function(e){
e.preventDefault();
update();
shadow = x+"px "+y+"px ";
if (op != 1){
if(op.length > 3){op=op.substring(0, 3);}
color="rgba("+r+","+g+","+b+","+op+")";
}
else{
color="rgb("+r+","+g+","+b+")";
}
if (blur != 0){shadow += blur+"px ";}
shadow += color;
$('#object').css("text-shadow",shadow);
$('#code-output').html("text-shadow:"+shadow+";");
});
在某些滑块的$(document).ready()中。
HTML:
<div class="container">
<div class="jumbotron text-center">
<h1 class="text-center"><span class='text-warning'>Text Shadow Generator V1.0</span></h1>
<p>Create awesome text shadow with pure CSS3.</p>
</div>
<div id="sliders">
<div class="row text-center">
<div class="col-md-4">
<h1>X-axis</h1>
<input type="range" id="x" min="-10" max="10" step="1" value="0" class='shadow-slider'>
</div>
<div class="col-md-4">
<h1>Y-axis</h1>
<input type="range" id="y" min="-10" max="10" step="1" value="0" class='shadow-slider'>
</div>
<div class="col-md-4">
<h1>Blur</h1>
<input type="range" id="blur" min="0" max="10" step="1" value="0" class='shadow-slider'>
</div>
</div>
<!--End for shadow axis and blur sliders-->
<div class="container" style="margin-top:1em;"><p id="object">All text shadows will be applied here</p></div>
<div class="row text-center">
<div class="col-md-3">
<h1>Red</h1>
<input type="range" id="red" min="0" max="255" step="1" value="0" class='shadow-slider'>
</div>
<div class="col-md-3">
<h1>Green</h1>
<input type="range" id="green" min="0" max="255" step="1" value="0" class='shadow-slider'>
</div>
<div class="col-md-3">
<h1>Blue</h1>
<input type="range" id="blue" min="0" max="255" step="1" value="0" class='shadow-slider'>
</div>
<div class="col-md-3">
<h1>Opacity</h1>
<input type="range" id="o" min="0" max="1" step="0.1" value="1" class='shadow-slider'>
</div>
</div>
</div>
问题是,当使用jquery addEventListener方法时,touchmove无效。有什么想法吗?
答案 0 :(得分:0)
addEventListener
不是jQuery中的函数,您可以将其替换为:
$('.shadow-slider').on("touchmove",function(e){
// your code here
});
addEventListener
适用于纯JS:
document.addEventListener('touchmove', function(e){
// your code here
});
或具有ID
的特定html标记document.getElementById('myDiv').addEventListener('touchmove', function(e){
// your code here
});